-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
If no subcommand, how to get args? #42
Comments
I'm having a similar problem. My program is run like so: But instead of running the root command with the path as an argument, it complains that the path is an invalid command.I tried using flags, but it seems that would require adding a flag (-p /home/test.txt) to the invocation. |
I'm also having this issue. Is having zero subcommands supported? It doesn't seem to be working. |
It isn't possible. The code treats the root command "special". I don't really love it. Root commands may only take flags and subcommands. Validation for subcommands is only done for root commands. Subcommands will be called with an argument instead of failing if an invalid sub-sub-command was intended, but typod. I'm thinking about what to do here in #86 But any kind of consistency is going to break previous behavior. Personally I'm leaning towards a 'takesNoArgs' flag which defaults to false. Meaning the root command, and all subcommands, would get unknown args. You would only get subcommand validation and complain if you set takesNoArgs=true |
We recently started to migrate from codegangsta / urfave CLI, and we love Cobra so far! But we have a couple of tools which are primarily designed to run other programs (think about something IMO what @ghodss described (and what's essentially how this works in codegangsta / urfave CLI) at #120 (comment) / #86 (comment) makes sense, or be able to specify a "default" command in any other way. Is there a workaround for this use case for now? |
I think this issue is also pretty much the same as #15 (as in, solving either would provide a solution / possible workaround for the other one). |
If you use my PR #284 and use |
@dnephin checked the PR and it's not exactly clear for me: does this work for the Root command too? |
Yes, it will work for the root command. The old args behaviour is defined in |
example:
Thanks!
The text was updated successfully, but these errors were encountered: