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

Is it possible to avoid to prefix the name of the file in the usage of the subcommand ? #564

Closed
cmoulliard opened this issue Aug 25, 2016 · 4 comments

Comments

@cmoulliard
Copy link

The following subcommand defined within the file litoria-generate.js script setup the usage

var program = require('commander'),
    $               = require('../lib/litoria.js');

program
    .description('generate html from the asciidoc file using html5 as backend')
    .usage('litoria <generate> [options]')
    .option('-b, --backend', 'backend - html5, docbook')
    .parse(process.argv);

as such

    .usage('litoria <generate> [options]')

But when I call the help for that subcommand, the usage is prefixed with the name of the file litoria-generate.

litoria generate --help

  Usage: litoria-generate litoria <generate> [options]

Is there a workaround to only display for the subcommand the command defined within the subcommand usage ?

@armoucar
Copy link

armoucar commented Jan 23, 2017

yep, it's kind of annoying that usage displays an invalid command.

My solutions was:

.usage('\n\n  $ pm install <generate> [options]')

Then it displays like:

Usage: pm-install 

$ pm install <generate> [options]

Options:

  -h, --help   output usage information
  -f, --force  force installation

@CedricReichenbach
Copy link

Usage is prefixed with the name property of the command, which defaults to the file name. I created a PR to make this settable through a chainable function: #605

As a (hacky) workaround, you can currently just override _name, but you probably shouldn't rely on that, as it's not part of the intended API:

var program = require('commander');

program._name = 'litoria generate';

program
    .description('generate html from the asciidoc file using html5 as backend')
    .usage('litoria <generate> [options]')
    .option('-b, --backend', 'backend - html5, docbook')
    .parse(process.argv);

@alexcanessa
Copy link

This issue should be closed as fixed with @CedricReichenbach's #605

@abetomo
Copy link
Collaborator

abetomo commented Sep 20, 2017

@alexcanessa Thank you for the reminder!

@abetomo abetomo closed this as completed Sep 20, 2017
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

5 participants