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

command with empty string should be the default command #303

Closed
justinmchase opened this issue Dec 10, 2014 · 7 comments
Closed

command with empty string should be the default command #303

justinmchase opened this issue Dec 10, 2014 · 7 comments

Comments

@justinmchase
Copy link

I would like it if you could specify an empty command name and have that be what is invoked if none is specified.

program
    .command('test')
    .action(function () { console.log('test'); });
program
    .command('*')
    .action(function () { console.log('unknown'); });
program
    .command('') // <- not currently supported
    .action(function () { console.log('default'); });

Then:
$ example test
test
$ example foo
unknown
$ example
default

Right now I am able to replace the last command with:

if(!program.args.length) {
    console.log('default');
}

But it has to go after the call to program.parse and it feels inelegant in comparison.

@natew
Copy link

natew commented Dec 24, 2014

👍

1 similar comment
@ButuzGOL
Copy link

ButuzGOL commented May 6, 2015

👍

@SomeKittens
Copy link
Collaborator

We don't plan to support this right now, but there's a workaround here: #338

@justinmchase
Copy link
Author

May I ask why not? Would you consider accepting a pull request? Could you at least add the work around from @goloroden to the wiki?

@gilbert
Copy link

gilbert commented Mar 28, 2019

Here's an easy workaround for this issue:

if (process.argv.length === 2) {
  process.argv.push('-h')
}

This causes the help text output to be the default, but you can replace -h with whatever command you want.

@slavafomin
Copy link

Why doesn't the Commander support the default command? This is a basic behavior for any CLI application.

@shadowspawn
Copy link
Collaborator

See #742 for the currently open issue.

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

No branches or pull requests

7 participants