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

Open
mfowlewebs opened this Issue Nov 12, 2015 · 4 comments

Comments

Projects
None yet
5 participants
@mfowlewebs

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

This comment has been minimized.

Show comment
Hide comment
@subwiz

subwiz 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.

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.

@steelbrain

This comment has been minimized.

Show comment
Hide comment

Bump

@ivanakimov

This comment has been minimized.

Show comment
Hide comment

+1

@szeck87

This comment has been minimized.

Show comment
Hide comment
@szeck87

szeck87 Jul 5, 2018

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.

szeck87 commented Jul 5, 2018

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.

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