-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remaining args / -- argument separator? #73
Comments
This was an oversight, but I will look into rectifying it. Thanks for bringing it to my attention, I'll keep you updated. |
I understand your example above, but in the referenced issue afterwards (https://github.com/amphp/aerys/issues/58) how would you expect something like that to come back? Just so I know we're on the same page.
|
I'm not too sure about the API. Eventually, we could have the argument named I prefer a |
@joetannenbaum any update on this? |
Hey @bwoebi, I guess my question is, would you like it to work something like this:
$climate->arguments->trailing();
// ['port' => 80, 'host' => 'localhost']
// or
// '--port 80 --host localhost' |
An unparsed variant. That's the point of the So basically: |
@joetannenbaum bump ...? |
Just put it into master, want to check it out before I tag it? $trailing_args = $climate->arguments->trailing(); |
Looks nice, but usually trailing args should also work without explicit Thanks! (See also initial example: |
@joetannenbaum so, what do you think? |
bump |
I'm sorry for the delay, I've been swamped at work trying to launch a big project. I'll get this up this week. |
bump |
I hear you, I apologize. CLImate will get love this week. |
This can be implemented manually by splitting the array if there's a |
This week? bump. |
I'm working on re-working the argument parser so that it's more readable and intuitive. The '--' version of the trailing arguments is in the current release (3.2.1), if you need the other part implemented prior to the re-write I'm happy to accept a pull request. |
@joetannenbaum any progress on this? |
@imbrish Hi Paul, I've taken over development of CLImate, I don't currently have this specific task scheduled, but I'll look at it as soon as I can. As Joe said, Pull Requests are always welcome 😄 |
Hi Craig! I think #85 is the best bet. Currently it's not possible to get an array of remaining arguments, even with Unfortunately rewriting whole parsing logic gonna be a big backward compatibility break :( |
I needed to get the unregistered args following the main command and ended up doing this: /**
* Match all the commands following the passed command.
*
* Example
* > `phy -d db pull main -x`
* Produces: [ 'pull', 'main' ]
*
* Example
* > `phy db pull-stuff --careful=true`
* Produces: [ 'pull-stuff' ]
*
* @param $argv
* @param $starting_command
*
* @return array
*/
function get_subsequent_commands( $argv, $starting_command ) {
$command_as_string = implode( ' ', $argv );
$pattern = "/{$starting_command}(\s(?!-)[\w\d-]+)+/";
preg_match( $pattern, $command_as_string, $matches );
if ( empty( $matches[0] ) ) {
return [];
}
$commands = $matches[0];
$commands = str_replace( $starting_command, '', $commands );
$commands = trim( $commands );
$command_chain = explode( ' ', $commands );
return $command_chain;
} This seems to work well enough. |
I'd like to be able to grab the trailing args:
Then I want to get an array
["foo", "bar"]
back.(
--
is common as an argument separator, like everything, including arguments with a leading-
, following is passed literally to somewhere else.)I've searched for it in the docs, but actually found no way how to grab every trailing arg. I've only found a way to grab a single arg...
Was this an oversight in the implementation or was there just some undocumented feature?
The text was updated successfully, but these errors were encountered: