yargs / yargs

yargs the modern, pirate-themed successor to optimist.
https://yargs.js.org/
MIT License
11.09k stars 992 forks source link

Help text for string arguments could/should show variable in square brackets #833

Open stevage opened 7 years ago

stevage commented 7 years ago

I have an argument specified like:

    .option('id', {
        describe: 'Only update this dataset ID',
        type: 'string',
        requiresArg: true
    })

The help text comes out as:

  --id           Only update this dataset ID                            [string]

IMHO, it should be something like:

  --id [datasetID]       Only update this dataset ID

Is there a way to achieve this? Could there be?

bmundt6 commented 4 years ago

I would still like to see this implemented if possible; the answer given in https://github.com/yargs/yargs/issues/730 to use an example doesn't seem as natural as just introducing a metavar name that is printed with the usage string. e.g., as per grep:

.option('B', {
    type: 'number',
    alias: ['before-context'],
    metavar: 'num',
    describe: 'Print num lines of leading context before each match.',
})

Would yield the usage string:

-B num, --before-context=num             Print num lines of leading context before each match.

Even better yet, if we could use a template like $0 for default command usage:

    describe: 'Print $VAR lines of leading context before each match.'
rivy commented 2 years ago

@stevage @bmundt6 , I'm hacking this behavior by using an alias with leading backspaces ...

// ... 
.option('formatter', {
    alias: ['f', '\b\b\b\b <command>'], // *hack* use backspaces to fake an option argument description
    choices: ['default', 'all', 'deno', 'dprint'],
    describe: `Select the code formatter ('default' == 'dprint')`,
    nargs: 1,
    type: 'string',
});

@mleguen @bcoe , any likelyhood that this could be added to yargs?