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

Default subcommand not possible in example #469

Closed
mfowlewebs opened this issue Nov 12, 2015 · 9 comments
Closed

Default subcommand not possible in example #469

mfowlewebs opened this issue Nov 12, 2015 · 9 comments

Comments

@mfowlewebs
Copy link

In Example we have a bunch of subcommands listed, however there is no way to make any of them the default.

I've tried, for example, changing the final subcommand to .command('*', undefined, {isDefault: true}) however it seems to have no impact. Providing a description does worse: it causes file-* does not exist to be returned for either * or default.

@subwiz
Copy link

subwiz commented Apr 17, 2016

Facing same problem. I have:

program.command('help', null, {isDefault:true})
  .description('display help information.')
  .action(function(){
    program.outputHelp();
  });

program.command('*', null, {noHelp:true})
  .action(function(cmd){
    console.error('unrecognized command: ' + cmd);
    program.outputHelp();
  });

noHelp is working as expected, while isDefault has no impact.

@jd327
Copy link

jd327 commented Apr 6, 2017

+1

@stevenzeck
Copy link

Is this going to be looked at? It seems like

commander.js/index.js

Lines 169 to 191 in aaa447a

Command.prototype.command = function(name, desc, opts) {
if (typeof desc === 'object' && desc !== null) {
opts = desc;
desc = null;
}
opts = opts || {};
var args = name.split(/ +/);
var cmd = new Command(args.shift());
if (desc) {
cmd.description(desc);
this.executables = true;
this._execs[cmd._name] = true;
if (opts.isDefault) this.defaultExecutable = cmd._name;
}
cmd._noHelp = !!opts.noHelp;
this.commands.push(cmd);
cmd.parseExpectedArgs(args);
cmd.parent = this;
if (desc) return this;
return cmd;
};
is being called three times. The first time it correctly finds the isDefault flag, the last two are undefined.

@padcom
Copy link

padcom commented Dec 1, 2018

Is this package at all maintained anymore? This is really a critical issue and is still not fixed.

@paulmelnikow
Copy link

These days I'm using:

And a more popular alternative is:

@shadowspawn
Copy link
Collaborator

The isDefault functionality is currently only supported for git-style subcommands. I am closing this issue in favour of #742 which identifies the limitation in the title.

@padcom
Copy link

padcom commented Apr 23, 2019

I know this is a lot to ask but could you elaborate (provide a short example maybe?) what does it mean git-style subcommands? I am mighty confused...

@shadowspawn
Copy link
Collaborator

@shadowspawn
Copy link
Collaborator

Support for a default command with action handler shipped in Commander 5.0.0: #742

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