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

command.default(name) doesn't seem to work as expected #655

Open
justinmchase opened this issue Aug 6, 2023 · 1 comment
Open

command.default(name) doesn't seem to work as expected #655

justinmchase opened this issue Aug 6, 2023 · 1 comment

Comments

@justinmchase
Copy link

I setup a command with two sub commands and then added

command.default(subCommands[0].name)

Then I am running my app without any arguments and it does not seem to work, it just prints out the usage and exits as it did before. If I add a single argument it executes the correct sub command.

The documentation doesn't seem to have any examples of how to use the command.default(name) function either.

@NfNitLoop
Copy link

A year later, I had a similar problem. .default() was silently failing in some cases, and giving odd errors in others. I think it was because it was getting registered as a default for the sub-commands?

For those that end up here from web searches, here's what ended up working for me, using jsr:@cliffy/command@1.0.0-rc.5:

    const cmd = new Command()
        .default("help")

    // Add all my individual commands like:
    cmd.command("foo")
        .description("whatever")
        .option(/* etc */)
        .action(fooCommand) 
        
    // Don't forget to add that default "help" command:
    cmd.command("help")
        .description("Show this help.")
        .action(() => {
            cmd.showHelp()
        })

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

2 participants