-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Match help information with .parse({ from })
#2276
Comments
I am not sure what the problem is. Can you give an example of what you are trying to do and what you see? |
I will post an actual example when I am back at my computer. The problem is that help prefixes the command with the program name, even though it parses just the command. Parsing user input actually fails if you add the name of the program before it. |
Here is the Screencast I made earlier. As you see what help says is not what you have to type to execute a command. |
Ah, I see. The help does assume it should show the root command (program) in the usage. A quick hack would be to set the program name to a space. There will be some extra spaces in the displayed usage, but really easy! program.name(' '); A full solution is to change the method building the usage. (You could leave out the // Do now include the "program name" since it does
// not make sense in our usage.
program.configureHelp({
commandUsage: (cmd) => {
if (!cmd.parent) return cmd.usage();
let cmdName = cmd.name();
if (cmd._aliases[0]) {
cmdName = cmdName + '|' + cmd._aliases[0];
}
let ancestorCmdNames = '';
for (
let ancestorCmd = cmd.parent;
ancestorCmd && ancestorCmd.parent;
ancestorCmd = ancestorCmd.parent
) {
ancestorCmdNames = ancestorCmd.name() + ' ' + ancestorCmdNames;
}
return ancestorCmdNames + cmdName + ' ' + cmd.usage();
}}
);
const fooCommand = program.command('foo');
const barCommand = fooCommand.command('bar'); $ node repl.mjs --help | head -n 1
Usage: [options] [command]
$ node repl.mjs foo --help | head -n 1
Usage: foo [options] [command]
$ node repl.mjs foo bar --help | head -n 1
Usage: foo bar [options] |
Displayed help information does not align with what the user input actually is, in case
from
property is set during parsing. Help still shows the main command fromnode
perspective.The text was updated successfully, but these errors were encountered: