Skip to content

Add support for adding option to subcommand#1

Open
canmor wants to merge 1 commit intolijinma:masterfrom
canmor:master
Open

Add support for adding option to subcommand#1
canmor wants to merge 1 commit intolijinma:masterfrom
canmor:master

Conversation

@canmor
Copy link

@canmor canmor commented Aug 14, 2018

Implements adding option to sub command, following is an example:

$program = new Commander();

$program
    ->version('0.0.1');

$program
    ->command('rmdir <dir>', 'remove dir')
    ->option('-r, --recursive', 'remove recursively')
    ->action(
        function ($dir) use ($program) {
            foreach ($program->_subCmds as $cmd) {
                if ($cmd->_name == 'rmdir') {
                    if ($cmd->recursive) {
                        // recursively implement goes here...
                    }
                    else {
                        // normal implement goes here...
                    }
                    break;
                }
            }
        }
    );

$program->parse($argv);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant