Skip to content
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

add getCommands API for all registered commands #852

Open
rawbin- opened this issue Apr 12, 2017 · 2 comments
Open

add getCommands API for all registered commands #852

rawbin- opened this issue Apr 12, 2017 · 2 comments

Comments

@rawbin-
Copy link

rawbin- commented Apr 12, 2017

var allCommands = yargs.getCommands();
if(allCommands.indexOf(argv[0]) === -1){
    yargs.showHelp();
}

@bcoe
Copy link
Member

bcoe commented Apr 13, 2017

@rawbin- once we address #853, you should be able to use .strict() to get the behavior you've outlined above.

however, I do like the idea of adding a method for getting all known commands (could see this being handy for some CLIs).

@rawbin-
Copy link
Author

rawbin- commented Jun 28, 2017

this seems not work, do I get something in wrong way?

I just want when I run with cmd pack cmd min,it goes as is, and when I run with cmd xxx it show the help,just as the commented code do

var yargsObj = require('yargs');
var allCommands = ['pack'];
var globalArgv = yargsObj.strict()
    .usage('Usage: $0 <command> [options]')
    .command('pack', 'pack the code', function (yargs) {
        console.log('hit pack cmd')
    })
    .command('min', 'min the code', function (yargs) {
        console.log('hit min cmd')
    })
    .help('h').alias('h', 'help')
    .argv;

console.log(globalArgv._)

// if (globalArgv._.length === 0 || allCommands.indexOf(globalArgv._[0]) === -1) {
//     yargsObj.showHelp();
// }

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

No branches or pull requests

2 participants