<?php
/**
* Logs command-line options for dry-run scenarios with manual overrides.
*
* @param array $argv Command-line arguments.
*/
function logDryRunOptions(array $argv): void
{
$log = [];
// Store all command-line arguments
$log['all_args'] = $argv;
// Iterate through arguments, extracting option values
for ($i = 1; $i < count($argv); $i++) {
$arg = $argv[$i];
if (strpos($arg, '-') === 0) {
// It's an option
$optionName = substr($arg, 1); // Remove the hyphen
$log[$optionName] = $argv[$i + 1] ?? null; // Get the value, handling missing values
$i += 1; // Skip the option value
}
}
// Log the extracted options
echo "<pre>";
print_r($log);
echo "</pre>";
}
// Example usage: (Uncomment to test)
/*
if (php_sapi_name() == 'cli') {
$logDryRunOptions($argv);
}
*/
?>
Add your comment