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

Several 'help' fixes #51

Closed
wants to merge 2 commits into from
Closed

Conversation

fabianofranz
Copy link
Contributor

Need to make sure --help is registered before calling pflags which tries to handle the help flag itself.

Find() must be aware of the special command help and consider the context it's being called in order to display the help for the proper command (instead of root).

@spf13
Copy link
Owner

spf13 commented Feb 11, 2015

@fabianofranz This isn't passing the tests. Can you revisit it and make it pass.

@fabianofranz fabianofranz force-pushed the help_fixes branch 3 times, most recently from 37b839e to 55a7e5d Compare April 7, 2015 17:27
@fabianofranz
Copy link
Contributor Author

@spf13 Good to go.

return true
}
}
return false
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this HasRunnableSubCommands() ? Why the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I wasn't aware of HasRunnableSubCommands(). Might have happened after I first created this PR. Reverted to the original behavior.

@@ -370,6 +371,9 @@ func (c *Command) Find(arrs []string) (*Command, []string, error) {
// only accept a single prefix match - multiple matches would be ambiguous
if len(matches) == 1 {
return innerfind(matches[0], argsMinusX(args, argsWOflags[0]))
} else if len(matches) == 0 && len(args) > 0 && args[0] == "help" {
// special case help command
return innerfind(c, argsMinusX(append(args, "--help"), argsWOflags[0]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is interesting. Before this change.

command help subcommand - works, shows help for subcommand
command subcommand help - fails, because 'help' is an unknown subsubcommand

Are we certain we want the later? (I personally like it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this PR to revert that piece of code (on a separate commit so we don't loose it), since it may result in behavior not valid for every scenario.

The "help" string could be a valid argument that does not mean help. Using git add as an example:

git add help

Means I want to add the file called "help", which is perfectly plausible. I do not want the equivalent of git add --help here.

@eparis
Copy link
Collaborator

eparis commented Apr 7, 2015

i still can't figure out how to write a test that is somehow 'wrong' can you help me figure out and example fabio?

@@ -798,7 +806,7 @@ func (c *Command) Flags() *flag.FlagSet {
c.flagErrorBuf = new(bytes.Buffer)
}
c.flags.SetOutput(c.flagErrorBuf)
c.PersistentFlags().BoolVarP(&c.helpFlagVal, "help", "h", false, "help for "+c.Name())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the change here is that you are calling c.mergePersistentFlags() here. (And then making sure mergePersistentFlags() won't bug later)

So is there a real bug that somehow we missed a meaningful and necessary c.mergePersistendFlags() call somewhere else? I really wish I knew how to trigger it...

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

Successfully merging this pull request may close these issues.

3 participants