<?php
/**
* Sorts command-line options for scheduled runs.
*
* @param array $options An associative array of options.
* @return array A sorted array of options.
*/
function sortScheduledRunOptions(array $options): array
{
// Define the order of options. Prioritize essential ones.
$sortOrder = [
'--cron' => 0, // Cron schedule
'--start-date' => 1, // Starting date
'--end-date' => 2, // Ending date
'--task' => 3, // Task to run
'--output-file' => 4, // Output file
'--log-file' => 5, // Log file
'--priority' => 6, //Priority
'--tags' => 7, //Tags
'--dry-run' => 8, // Dry run mode
'--verbose' => 9, // Verbose output
'--help' => 10, // Help message
];
// Sort the options array based on the defined order.
usort($options, function ($a, $b) use ($sortOrder) {
return $sortOrder[$a] - $sortOrder[$b];
});
return $options;
}
// Example usage (for testing):
/*
$options = [
'--dry-run' => true,
'--task' => 'backup',
'--start-date' => '2024-01-01',
'--cron' => '0 0 * * *',
'--help' => true,
'--output-file' => '/tmp/backup.tar.gz',
'--log-file' => '/var/log/backup.log',
'--priority' => 'high',
'--tags' => ['backup', 'important'],
];
$sortedOptions = sortScheduledRunOptions($options);
print_r($sortedOptions);
*/
?>
Add your comment