Is there a native \"PHP way\" to parse command arguments from a string? For example, given the following string:
foo \"bar \\\"baz
I wrote some packages for console interactions:
Arguments parsing
There is a package that does the whole arguments parsing thing weew/php-console-arguments
Example:
$parser = new ArgumentsParser();
$args = $parser->parse('command:name arg1 arg2 --flag="custom \"value" -f="1+1=2" -vvv');
$args will be an array:
['command:name', 'arg1', 'arg2', '--flag', 'custom "value', '-f', '1+1=2', '-v', '-v', '-v']
Arguments can be grouped:
$args = $parser->group($args);
$args will become:
['arguments' => ['command:name', 'arg1', 'arg2'], 'options' => ['--flag' => 1, '-f' => 1, '-v' => 1], '--flag' => ['custom "value'], '-f' => ['1+1=2'], '-v' => []]
It can do much more, just check the readme.
Output styling
You might need a package for output styling weew/php-console-formatter
Console application
Packages above can be used standalone or in combination with a fancy console application skeleton weew/php-console
Note: This solutions are not native but might still be useful to some people.