Conversation
You have to explicitly ask for help using the help flags. Otherwise, `gh` will just print the authentication message.
mislav
left a comment
There was a problem hiding this comment.
Could this entire check be moved into cmdutil.IsAuthCheckEnabled using Cobra introspection features?
- If the command to be executed has the name
help, auth check should be skipped. This would handlegh help <command> - If the command to be executed has a
--helpflag (as determined bycmd.Flags().Lookup("help")) and the flag is enabled, auth check should be skipped. This will transparently handle-has well.
When I run func IsAuthCheckEnabled(cmd *cobra.Command) bool {
log.SetFlags(log.Llongfile)
log.Printf("%+v", cmd.Flags().Lookup("help"))
log.Printf("%+v", cmd.Flags())
...I get: I tried looking for an appropriate Cobra method, but it seems the flags aren't getting set somewhere. Am I missing something obvious? If I wasn't depending on |
Currently, this still checks authentication, but we skip the authentication message and exit normally.
The linter picked up that the error value from cmd.Help() isn't checked. Even though cmd.Help() returns an error value, it's always nil. The inner HelpFunc() function directly prints the error message instead of returning an error value.
|
I've updated the pull request and the pull request description. My latest commits now skip the authentication message and just print the help page. We still do the authentication check though. I've dug around a little more, but I'm still not sure why |
With auth check being done via Cobra hooks, it is automatically skipped for non-runnable commands and `-h/--help` flag usage.
The command is now non-runnable, meaning it's exempt from auth check.
|
Thanks for looking into all this. I didn't realize Cobra didn't make this more straightforward. I've pushed some changes to avoid manually checking for |
At the moment, the "help footer" doesn't add any new information, but if additional flags are added later, they should appear in the footer. This change restores this help footer: ```shell USAGE gh actions [flags] INHERITED FLAGS --help Show help for command LEARN MORE Use 'gh <command> <subcommand> --help' for more information about a command. Read the manual at https://cli.github.com/manual ```
8eb040d to
89ce78e
Compare
|
No problem! I'm still trying to understand Cobra and the The latest commit adds back the help "footer" that shows usage, inherited flags, etc. At the moment, the footer doesn't provide any new information, but if you add other flags to |
Trailing whitespace is significant in Markdown. This reverts commit 682c15d.
|
@chemotaxis I've reverted whitespace changes to the help doc because we feed all docs as Markdown to our documentation site, and whitespace (even trailing) in Markdown is significant. |
Sorry, I didn't realize that! |
It looks like a similar check is done in ColorScheme.Bold() where it checks whether the scheme is enabled or not.
In this branch, we originally avoided the authentication check by getting rid of the run method attached to the command. Instead of that, this commit makes the `gh actions` command runnable again, but the authentication is disabled with `cmdutil.DisableAuthCheck`; this mirrors what's done for `gh version`. `gh actions` and `gh actions [-h | --help]` all work while being logged out. In addition, this commit restores some original behavior. Before this commit, the help footer (usage, inherited flags, etc.) is appended whether you use `gh actions` or `gh actions --help`. This commit restores the original behavior where `gh actions` prints just the text for the actions explanation, but `gh actions --help` appends the help footer.
4d79206 to
b0f58d0
Compare
|
This pull request now has two main fixes:
I was looking over the changes one last time and noticed the The latest commit makes This also restores the original print behavior where Feel free to revert b0f58d0, but I think this is a better solution since it maintains the original print behavior for |
Fixes #3823.
Testing note: I logged out first using
gh auth logout.Currently, if you're logged out, you can't access any help pages with the flags
--helpand-hfor commands that require authentication.While
gh help actionsworks,gh actions --helpdoes not.If you try
gh actions --help, you get a message about authentication:This pull request allows you to explicitly ask for help pages using the help flags, even if you are logged out.
After applying this change,
gh actionswill still print the same message above, butgh actions --helpwill now print this: