GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Improve `run list` doc with available `--json` fields by babakks · Pull Request #8934 · cli/cli Conversation
Member
This PR adds the name of available JSON fields to the command doc. Fixes #8588
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
|
@williammartin Thanks for the comment. I agree with the second approach being more useful. I came up with this simple string formatting function, named Now the doc looks like this: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@williammartin I checked all references of
If you're okay with the changes in this PR, I can apply the same change for the above commands as well. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for trying this out. I'm in two minds about this change. Here's what it looks like to me:
It seems like a lot of help real estate for what the user can discover by providing `--json` with no args, as is documented in [`gh help formatting`](https://cli.github.com/manual/gh_help_formatting):
The --json flag requires a comma separated list of fields to fetch. To view the possible JSON field names for a command omit the string argument to the --json flag when you run the command
This is linked to from the --template flag usage:
-t, --template string Format JSON output using a Go template; see "gh help formatting"
Maybe we should just include "; see "gh help formatting on the usage of --jq and --json?
On the other hand, being able to see the available fields at a glance in the manual or help is also quite nice for ctrl+F and if you don't have the CLI to hand right at that moment.
I think I'd like @andyfeller to chime in here to choose a direction.
Finally, if we did proceed with this, I also had a slightly different approach in mind. In my idea, when we pass the cmd to AddJSONFlags, it would update the Long field with this text concatenated. This way there's no way for us to either forget to add this content to a command that has the JSON flags, or to provide different slices by accident (e.g. when copying and pasting commands).
It would also mean that every command you listed above and in future get the behaviour with no further changes needed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@williammartin Thanks. I, too, agree that it should only be seen in the long doc. And also I liked the idea of doing it in the One more argument in favor of listing available fields in the docs is that the online CLI manual would also benefit from it. I'll wait for @andyfeller's opinion on this and will then update the requested changes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I love how we both came to the same conclusion as I really prefer minimizing additional changes needed by commands that can fall out of sync. However, I'd prefer a separate section lower in the help usage for JSON fields over tacking it onto
Mock up of
|
| func rootHelpFunc(f *cmdutil.Factory, command *cobra.Command, args []string) { | |
| flags := command.Flags() | |
| if isRootCmd(command) { | |
| if versionVal, err := flags.GetBool("version"); err == nil && versionVal { | |
| fmt.Fprint(f.IOStreams.Out, command.Annotations["versionInfo"]) | |
| return | |
| } else if err != nil { | |
| fmt.Fprintln(f.IOStreams.ErrOut, err) | |
| hasFailed = true | |
| return | |
| } | |
| } | |
| cs := f.IOStreams.ColorScheme() | |
| if help, _ := flags.GetBool("help"); !help && !command.Runnable() && len(flags.Args()) > 0 { | |
| nestedSuggestFunc(f.IOStreams.ErrOut, command, flags.Args()[0]) | |
| hasFailed = true | |
| return | |
| } | |
| namePadding := 12 | |
| type helpEntry struct { | |
| Title string | |
| Body string | |
| } | |
| longText := command.Long | |
| if longText == "" { | |
| longText = command.Short | |
| } | |
| if longText != "" && command.LocalFlags().Lookup("jq") != nil { | |
| longText = strings.TrimRight(longText, "\n") + | |
| "\n\nFor more information about output formatting flags, see `gh help formatting`." | |
| } | |
| helpEntries := []helpEntry{} | |
| if longText != "" { | |
| helpEntries = append(helpEntries, helpEntry{"", longText}) | |
| } | |
| helpEntries = append(helpEntries, helpEntry{"USAGE", command.UseLine()}) | |
| if len(command.Aliases) > 0 { | |
| helpEntries = append(helpEntries, helpEntry{"ALIASES", strings.Join(command.Aliases, "\n")}) | |
| } | |
| for _, g := range GroupedCommands(command) { | |
| var names []string | |
| for _, c := range g.Commands { | |
| names = append(names, rpad(c.Name()+":", namePadding)+c.Short) | |
| } | |
| helpEntries = append(helpEntries, helpEntry{ | |
| Title: strings.ToUpper(g.Title), | |
| Body: strings.Join(names, "\n"), | |
| }) | |
| } | |
| if isRootCmd(command) { | |
| var helpTopics []string | |
| if c := findCommand(command, "actions"); c != nil { | |
| helpTopics = append(helpTopics, rpad(c.Name()+":", namePadding)+c.Short) | |
| } | |
| for _, helpTopic := range HelpTopics { | |
| helpTopics = append(helpTopics, rpad(helpTopic.name+":", namePadding)+helpTopic.short) | |
| } | |
| sort.Strings(helpTopics) | |
| helpEntries = append(helpEntries, helpEntry{"HELP TOPICS", strings.Join(helpTopics, "\n")}) | |
| } | |
| flagUsages := command.LocalFlags().FlagUsages() | |
| if flagUsages != "" { | |
| helpEntries = append(helpEntries, helpEntry{"FLAGS", dedent(flagUsages)}) | |
| } | |
| inheritedFlagUsages := command.InheritedFlags().FlagUsages() | |
| if inheritedFlagUsages != "" { | |
| helpEntries = append(helpEntries, helpEntry{"INHERITED FLAGS", dedent(inheritedFlagUsages)}) | |
| } | |
| if _, ok := command.Annotations["help:arguments"]; ok { | |
| helpEntries = append(helpEntries, helpEntry{"ARGUMENTS", command.Annotations["help:arguments"]}) | |
| } | |
| if command.Example != "" { | |
| helpEntries = append(helpEntries, helpEntry{"EXAMPLES", command.Example}) | |
| } | |
| if _, ok := command.Annotations["help:environment"]; ok { | |
| helpEntries = append(helpEntries, helpEntry{"ENVIRONMENT VARIABLES", command.Annotations["help:environment"]}) | |
| } | |
| helpEntries = append(helpEntries, helpEntry{"LEARN MORE", heredoc.Docf(` | |
| Use %[1]sgh <command> <subcommand> --help%[1]s for more information about a command. | |
| Read the manual at https://cli.github.com/manual | |
| `, "`")}) | |
| out := f.IOStreams.Out | |
| for _, e := range helpEntries { | |
| if e.Title != "" { | |
| // If there is a title, add indentation to each line in the body | |
| fmt.Fprintln(out, cs.Bold(e.Title)) | |
| fmt.Fprintln(out, text.Indent(strings.Trim(e.Body, "\r\n"), " ")) | |
| } else { | |
| // If there is no title print the body as is | |
| fmt.Fprintln(out, e.Body) | |
| } | |
| fmt.Fprintln(out) | |
| } | |
| } |
man ...Lines 181 to 207 in 6f35082
| func genMan(cmd *cobra.Command, header *GenManHeader) []byte { | |
| cmd.InitDefaultHelpCmd() | |
| cmd.InitDefaultHelpFlag() | |
| // something like `rootcmd-subcmd1-subcmd2` | |
| dashCommandName := strings.Replace(cmd.CommandPath(), " ", "-", -1) | |
| buf := new(bytes.Buffer) | |
| manPreamble(buf, header, cmd, dashCommandName) | |
| for _, g := range root.GroupedCommands(cmd) { | |
| fmt.Fprintf(buf, "# %s\n", strings.ToUpper(g.Title)) | |
| for _, subcmd := range g.Commands { | |
| fmt.Fprintf(buf, "`%s`\n: %s\n\n", manLink(subcmd), subcmd.Short) | |
| } | |
| } | |
| manPrintOptions(buf, cmd) | |
| if len(cmd.Example) > 0 { | |
| buf.WriteString("# EXAMPLE\n") | |
| buf.WriteString(fmt.Sprintf("```\n%s\n```\n", cmd.Example)) | |
| } | |
| if cmd.HasParent() { | |
| buf.WriteString("# SEE ALSO\n") | |
| buf.WriteString(fmt.Sprintf("`%s`\n", manLink(cmd.Parent()))) | |
| } | |
| return buf.Bytes() | |
| } |
Lines 111 to 153 in 6f35082
| // genMarkdownCustom creates custom markdown output. | |
| func genMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error { | |
| fmt.Fprint(w, "{% raw %}") | |
| fmt.Fprintf(w, "## %s\n\n", cmd.CommandPath()) | |
| hasLong := cmd.Long != "" | |
| if !hasLong { | |
| fmt.Fprintf(w, "%s\n\n", cmd.Short) | |
| } | |
| if cmd.Runnable() { | |
| fmt.Fprintf(w, "```\n%s\n```\n\n", cmd.UseLine()) | |
| } | |
| if hasLong { | |
| fmt.Fprintf(w, "%s\n\n", cmd.Long) | |
| } | |
| for _, g := range root.GroupedCommands(cmd) { | |
| fmt.Fprintf(w, "### %s\n\n", g.Title) | |
| for _, subcmd := range g.Commands { | |
| fmt.Fprintf(w, "* [%s](%s)\n", subcmd.CommandPath(), linkHandler(cmdManualPath(subcmd))) | |
| } | |
| fmt.Fprint(w, "\n\n") | |
| } | |
| if err := printOptions(w, cmd); err != nil { | |
| return err | |
| } | |
| fmt.Fprint(w, "{% endraw %}\n") | |
| if len(cmd.Example) > 0 { | |
| fmt.Fprint(w, "### Examples\n\n{% highlight bash %}{% raw %}\n") | |
| fmt.Fprint(w, cmd.Example) | |
| fmt.Fprint(w, "{% endraw %}{% endhighlight %}\n\n") | |
| } | |
| if cmd.HasParent() { | |
| p := cmd.Parent() | |
| fmt.Fprint(w, "### See also\n\n") | |
| fmt.Fprintf(w, "* [%s](%s)\n", p.CommandPath(), linkHandler(cmdManualPath(p))) | |
| } | |
| return nil | |
| } |
gh referencecli/pkg/cmd/root/help_reference.go
Lines 54 to 72 in 6f35082
| func cmdRef(w io.Writer, cmd *cobra.Command, depth int) { | |
| // Name + Description | |
| fmt.Fprintf(w, "%s `%s`\n\n", strings.Repeat("#", depth), cmd.UseLine()) | |
| fmt.Fprintf(w, "%s\n\n", cmd.Short) | |
| // Flags | |
| // TODO: fold in InheritedFlags/PersistentFlags, but omit `--help` due to repetitiveness | |
| if flagUsages := cmd.Flags().FlagUsages(); flagUsages != "" { | |
| fmt.Fprintf(w, "```\n%s````\n\n", dedent(flagUsages)) | |
| } | |
| // Subcommands | |
| for _, c := range cmd.Commands() { | |
| if c.Hidden { | |
| continue | |
| } | |
| cmdRef(w, c, depth+1) | |
| } | |
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@andyfeller and I discussed this on Slack and we agree that including it in a separate section of the help is the best option here. However, we think it would be better to provide a compressed form as you have done to avoid annoying users by scrolling past the most important sections when there are a lot of fields. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
7c15e62 to
05a87b9
Compare
|
@williammartin @andyfeller Thanks for clarifying this. Since this PR is no longer just about the The "JSON Fields" section is now included in Markdown (website format), man pages, and For this to work, within the I've also moved the newly created Different docs (for
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Signed-off-by: Babak K. Shandiz <[email protected]>
|
@andyfeller I couldn't ask for your review from the sidebar. Could you please have a look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Thank you for your patience, @babakks, going to get this done now 🙇 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@babakks : once again, thank you for improving the GitHub CLI user experiences ❤️
Capturing examples of the updated output looks good:
... --help$ ./bin/gh repo list --help List repositories owned by a user or organization. Note that the list will only include repositories owned by the provided argument, and the `--fork` or `--source` flags will not traverse ownership boundaries. For example, when listing the forks in an organization, the output would not include those owned by individual users. For more information about output formatting flags, see `gh help formatting`. USAGE gh repo list [<owner>] [flags] ALIASES ls FLAGS --archived Show only archived repositories --fork Show only forks -q, --jq expression Filter JSON output using a jq expression --json fields Output JSON with the specified fields -l, --language string Filter by primary coding language -L, --limit int Maximum number of repositories to list (default 30) --no-archived Omit archived repositories --source Show only non-forks -t, --template string Format JSON output using a Go template; see "gh help formatting" --topic strings Filter by topic --visibility string Filter by repository visibility: {public|private|internal} INHERITED FLAGS --help Show help for command JSON FIELDS assignableUsers, codeOfConduct, contactLinks, createdAt, defaultBranchRef, deleteBranchOnMerge, description, diskUsage, forkCount, fundingLinks, hasDiscussionsEnabled, hasIssuesEnabled, hasProjectsEnabled, hasWikiEnabled, homepageUrl, id, isArchived, isBlankIssuesEnabled, isEmpty, isFork, isInOrganization, isMirror, isPrivate, isSecurityPolicyEnabled, isTemplate, isUserConfigurationRepository, issueTemplates, issues, labels, languages, latestRelease, licenseInfo, mentionableUsers, mergeCommitAllowed, milestones, mirrorUrl, name, nameWithOwner, openGraphImageUrl, owner, parent, primaryLanguage, projects, projectsV2, pullRequestTemplates, pullRequests, pushedAt, rebaseMergeAllowed, repositoryTopics, securityPolicyUrl, squashMergeAllowed, sshUrl, stargazerCount, templateRepository, updatedAt, url, usesCustomOpenGraphImage, viewerCanAdminister, viewerDefaultCommitEmail, viewerDefaultMergeMethod, viewerHasStarred, viewerPermission, viewerPossibleCommitEmails, viewerSubscription, visibility, watchers LEARN MORE Use `gh <command> <subcommand> --help` for more information about a command. Read the manual at https://cli.github.com/manual
$ ./bin/gh issue view --help Display the title, body, and other information about an issue. With `--web` flag, open the issue in a web browser instead. For more information about output formatting flags, see `gh help formatting`. USAGE gh issue view {<number> | <url>} [flags] FLAGS -c, --comments View issue comments -q, --jq expression Filter JSON output using a jq expression --json fields Output JSON with the specified fields -t, --template string Format JSON output using a Go template; see "gh help formatting" -w, --web Open an issue in the browser INHERITED FLAGS --help Show help for command -R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format JSON FIELDS assignees, author, body, closed, closedAt, comments, createdAt, id, labels, milestone, number, projectCards, projectItems, reactionGroups, state, title, updatedAt, url LEARN MORE Use `gh <command> <subcommand> --help` for more information about a command. Read the manual at https://cli.github.com/manual
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if _, ok := command.Annotations["help:json-fields"]; ok { | ||
| fields := strings.Split(command.Annotations["help:json-fields"], ",") | ||
| helpEntries = append(helpEntries, helpEntry{"JSON FIELDS", text.FormatSlice(fields, 80, 0, "", "", true)}) | ||
| } | ||
| if _, ok := command.Annotations["help:arguments"]; ok { | ||
| helpEntries = append(helpEntries, helpEntry{"ARGUMENTS", command.Annotations["help:arguments"]}) | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Realizing I don't know many commands where ARGUMENTS section would show up to say definitively if JSON fields should come before or after 🤔 ... my gut says JSON fields after arguments but will keep looking for an example as not the end of the world
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I agree that arguments should be printed before the JSON fields, since they're more like an appendix section. Since this is already merged, I can submit another PR for that if you say so.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Commandgh run list documentation missing information
There was an error while loading. Please reload this page.