<?php
/**
* CLI tool to manage maintenance file paths.
*/
// Function to display usage instructions.
function displayUsage() {
echo "Usage: php manage_maintenance_paths.php <option>\n";
echo "Options:\n";
echo " -set <path> <task> - Sets the path for a specific task.\n";
echo " -list - Lists all configured paths.\n";
echo " -remove <task> - Removes the path for a specific task.\n";
}
// Main function to handle CLI arguments.
function main() {
$config_file = 'maintenance_paths.php'; // File to store configurations
if (!file_exists($config_file)) {
file_put_contents($config_file, serialize(array())); // Create if it doesn't exist
}
$arguments = getopt('set:list:remove:', ['path:', 'task:']);
if (empty($arguments)) {
displayUsage();
return;
}
$paths = unserialize(file_get_contents($config_file));
switch ($arguments['set']) {
case 'set':
if (isset($arguments['path']) && isset($arguments['task'])) {
$path = $arguments['path'];
$task = $arguments['task'];
$paths[$task] = $path;
file_put_contents($config_file, serialize($paths));
echo "Path for task '$task' set to '$path'.\n";
} else {
displayUsage();
}
break;
case 'list':
if (!empty($paths)) {
echo "Maintenance Paths:\n";
foreach ($paths as $task => $path) {
echo " $task: $path\n";
}
} else {
echo "No paths configured.\n";
}
break;
case 'remove':
if (isset($arguments['task'])) {
$task = $arguments['task'];
if (isset($paths[$task])) {
unset($paths[$task]);
file_put_contents($config_file, serialize($paths));
echo "Path for task '$task' removed.\n";
} else {
echo "Task '$task' not found.\n";
}
} else {
displayUsage();
}
break;
default:
displayUsage();
}
}
// Run the main function.
if (PHP_SAPI == 'cli') {
main();
}
?>
Add your comment