You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following example the program never logs the last line if it is ran without commands but instead the help output is shown. This is unexpected behavior for me and since my actual CLI is an electron app I need it to run without commands too.
import { program, Command } from "commander";
const someCommand = new Command();
someCommand.name('name').argument("<string>").action((name) => console.log(`Hello ${name}`));
program.name("test").option("--irrelevant").addCommand(someCommand);
program.parse();
console.log(
"I would like to be logged if no command is passed to the CLI but unfortunately I'm not'."
);
The text was updated successfully, but these errors were encountered:
The default Commander behaviour when there are no arguments and you have subcommands and there is not a default command and there is not an action handler, is to show the help.
The simplest and most direct approach might be to test for this case yourself. In Electron, you can check defaultApp to work out what arguments were passed:
Thanks for the quick response! In my case I do need to parse the program because I have options (although no arguments). But adding an empty action handler to the top level command did the trick :).
I'm still not sure though whether this default behavior is what I would expect...
In the following example the program never logs the last line if it is ran without commands but instead the help output is shown. This is unexpected behavior for me and since my actual CLI is an electron app I need it to run without commands too.
The text was updated successfully, but these errors were encountered: