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

[Question] How to create a command and subcommands #1830

Closed
ramsesgarate opened this issue Dec 8, 2022 · 4 comments
Closed

[Question] How to create a command and subcommands #1830

ramsesgarate opened this issue Dec 8, 2022 · 4 comments

Comments

@ramsesgarate
Copy link

Hello, I would like to know if with commander it is possible to create a command that is executed with a main command that does not show the help and at the same time can have subcommands, I mean something like this:

$ my-cli
> hello world

$ my-cli -s
> hello world with option s

$ my-cli addition 2 2
> Result is 4

$ my-cli subtraction 8 2
> Result is 6
@shadowspawn
Copy link
Collaborator

Yes. that is a supported setup. The main command can have an action handler, and that will get called instead of showing the help when a subcommand is not specified.

@shadowspawn
Copy link
Collaborator

shadowspawn commented Dec 8, 2022

However, another approach is to specify a default command. A reason for doing it with a default command is to avoid having the top-level options as global options, like the -s in your example.

Does it make sense to do: my-cli -s addition 2 2 ?

See for example: #1616 #1750

@ramsesgarate
Copy link
Author

Thank you very much, leaving a default command worked for me!

@shadowspawn
Copy link
Collaborator

An answer was provided, and no further activity in a month. Closing this as resolved.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

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