nategood / commando

An Elegant CLI Library for PHP
MIT License
798 stars 80 forks source link

How do I determine when a flag is actually passed into the cmd session? #79

Open Erutan409 opened 6 years ago

Erutan409 commented 6 years ago

I know I must be missing something here, but what is the actual process of determining when a predefined flag is passed into the script endpoint? I've resorted to writing my own function to parse the $_SERVER['argc'] array.

Pretty sure the library is supposed to be taking care of this for me already, right?

Bored0ne commented 6 years ago

This is fixed in PR simply do $command->getTokens() to get an array of tokens sent in -> https://github.com/nategood/commando/pull/80

NeoVance commented 6 years ago

Sorry for the late response.

The commando instance contains the token values once they have been parsed by commando. you can use the parse function manually, or kick of the parsing by accessing the object like an array using the option or argument name as the key like so: $opValue = $command[$opName];

There are also a few useful functions for this like getArguments, getFlags, and getOptions that can be used. All of those functions will also force the token list to be parsed by Commando if it has not already done so.