I’ve spent a chunk of this evening working on a command line app written in PHP. I explored a heap of PHP command line libraries and frameworks, but found the easiest way to handle flags and variables was to just treat them as $_GET
parameters.
if (isset($argv)) {
parse_str(
join("&", array_slice($argv, 1)
), $_GET);
}
That checks to see if any $argv
’s are set, ignores the first one (which is just the script’s name, e.g. app.php
), and then reformats them as $_GET
parameters.
To add some polish, I’ve been using CLImate which makes it easy to format all kinds of output.