-
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
fix(args): Correct legacyArgs
logical errors
#1157
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -801,12 +801,6 @@ func (c *Command) execute(a []string) (err error) { | |
} | ||
} | ||
|
||
if !c.Runnable() { | ||
return flag.ErrHelp | ||
} | ||
|
||
c.preRun() | ||
|
||
argWoFlags := c.Flags().Args() | ||
if c.DisableFlagParsing { | ||
argWoFlags = a | ||
|
@@ -816,6 +810,12 @@ func (c *Command) execute(a []string) (err error) { | |
return err | ||
} | ||
|
||
if !c.Runnable() { | ||
return flag.ErrHelp | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving this after the parsing of the arguments seems right to me. The change will only impact commands that are not runnable which have the |
||
|
||
c.preRun() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more worrisome. I don't understand enough about This could be a backwards-compatibility issue. |
||
|
||
for p := c; p != nil; p = p.Parent() { | ||
if p.PersistentPreRunE != nil { | ||
if err := p.PersistentPreRunE(c, argWoFlags); err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot make this change as it will break backwards-compatibility.
Cobra does support commands that take args and sub-commands.
For example helm v2 has the
helm get
command:As you can see you can either pass it a sub-command, or you can pass it an argument.
As you mention, this can cause confusion so helm v3 no longer does that.
However it shows that some programs do use this feature and therefore we cannot change it.