From aae4a00769c30d0770c7aa0e781e786b66482769 Mon Sep 17 00:00:00 2001 From: Zack Sloane <10229009+zsloane@users.noreply.github.com> Date: Thu, 30 Nov 2023 16:28:51 -0500 Subject: [PATCH 1/6] Add default values to docs (web and man pages) --- internal/docs/man.go | 17 ++++- internal/docs/man_test.go | 103 +++++++++++++++++++++++++++++- internal/docs/markdown.go | 4 +- internal/docs/markdown_test.go | 112 +++++++++++++++++++++++++++++++++ 4 files changed, 232 insertions(+), 4 deletions(-) diff --git a/internal/docs/man.go b/internal/docs/man.go index 4864140f1..60caa8443 100644 --- a/internal/docs/man.go +++ b/internal/docs/man.go @@ -149,10 +149,23 @@ func manPrintFlags(buf *bytes.Buffer, flags *pflag.FlagSet) { } else { buf.WriteString(fmt.Sprintf("`--%s`", flag.Name)) } - if varname == "" { + + defval := "" + hiddenDefs := map[string]bool{ + "false": true, + "": true, + "[]": true, + } + if !hiddenDefs[flag.DefValue] { + defval = fmt.Sprintf(" (Default: %s)", flag.Value) + } + + if varname == "" && defval != "" { + buf.WriteString(fmt.Sprintf(" `%s`\n", strings.TrimSpace(defval))) + } else if varname == "" { buf.WriteString("\n") } else { - buf.WriteString(fmt.Sprintf(" `<%s>`\n", varname)) + buf.WriteString(fmt.Sprintf(" `<%s>%s`\n", varname, defval)) } buf.WriteString(fmt.Sprintf(": %s\n\n", usage)) }) diff --git a/internal/docs/man_test.go b/internal/docs/man_test.go index 84fc8cc57..80a1326c0 100644 --- a/internal/docs/man_test.go +++ b/internal/docs/man_test.go @@ -107,7 +107,7 @@ func TestManPrintFlagsHidesShortDeprecated(t *testing.T) { manPrintFlags(buf, c.Flags()) got := buf.String() - expected := "`--foo` ``\n: Foo flag\n\n" + expected := "`--foo` ` (Default: default)`\n: Foo flag\n\n" if got != expected { t.Errorf("Expected %q, got %q", expected, got) } @@ -130,6 +130,107 @@ func TestGenManTree(t *testing.T) { } } +func TestManPrintFlagsShowsDefaultValues(t *testing.T) { + type TestOptions struct { + Limit int + Template string + Fork bool + NoArchive bool + Topic []string + } + opts := TestOptions{} + // Int flag should show it + c := &cobra.Command{} + c.Flags().IntVar(&opts.Limit, "limit", 30, "Some limit") + + buf := new(bytes.Buffer) + manPrintFlags(buf, c.Flags()) + + got := buf.String() + expected := "`--limit` ` (Default: 30)`\n: Some limit\n\n" + if got != expected { + t.Errorf("Expected %q, got %q", expected, got) + } + + // Bool flag should hide it if default is false + c = &cobra.Command{} + c.Flags().BoolVar(&opts.Fork, "fork", false, "Show only forks") + + buf = new(bytes.Buffer) + manPrintFlags(buf, c.Flags()) + + got = buf.String() + expected = "`--fork`\n: Show only forks\n\n" + if got != expected { + t.Errorf("Expected %q, got %q", expected, got) + } + + // Bool flag should show it if default is true + c = &cobra.Command{} + c.Flags().BoolVar(&opts.NoArchive, "no-archived", true, "Hide archived") + + buf = new(bytes.Buffer) + manPrintFlags(buf, c.Flags()) + + got = buf.String() + expected = "`--no-archived` `(Default: true)`\n: Hide archived\n\n" + if got != expected { + t.Errorf("Expected %q, got %q", expected, got) + } + + // String flag should show it if default is not an empty string + c = &cobra.Command{} + c.Flags().StringVar(&opts.Template, "template", "T1", "Some template") + + buf = new(bytes.Buffer) + manPrintFlags(buf, c.Flags()) + + got = buf.String() + expected = "`--template` ` (Default: T1)`\n: Some template\n\n" + if got != expected { + t.Errorf("Expected %q, got %q", expected, got) + } + + // String flag should hide it if default is an empty string + c = &cobra.Command{} + c.Flags().StringVar(&opts.Template, "template", "", "Some template") + + buf = new(bytes.Buffer) + manPrintFlags(buf, c.Flags()) + + got = buf.String() + expected = "`--template` ``\n: Some template\n\n" + if got != expected { + t.Errorf("Expected %q, got %q", expected, got) + } + + // String slice flag should hide it if default is an empty slice + c = &cobra.Command{} + c.Flags().StringSliceVar(&opts.Topic, "topic", nil, "Some topics") + + buf = new(bytes.Buffer) + manPrintFlags(buf, c.Flags()) + + got = buf.String() + expected = "`--topic` ``\n: Some topics\n\n" + if got != expected { + t.Errorf("Expected %q, got %q", expected, got) + } + + // String slice flag should show it if default is not an empty slice + c = &cobra.Command{} + c.Flags().StringSliceVar(&opts.Topic, "topic", []string{"apples", "oranges"}, "Some topics") + + buf = new(bytes.Buffer) + manPrintFlags(buf, c.Flags()) + + got = buf.String() + expected = "`--topic` ` (Default: [apples,oranges])`\n: Some topics\n\n" + if got != expected { + t.Errorf("Expected %q, got %q", expected, got) + } +} + func assertLineFound(scanner *bufio.Scanner, expectedLine string) error { for scanner.Scan() { line := scanner.Text() diff --git a/internal/docs/markdown.go b/internal/docs/markdown.go index 41fe3a1fd..9c359e99b 100644 --- a/internal/docs/markdown.go +++ b/internal/docs/markdown.go @@ -50,13 +50,14 @@ type flagView struct { Name string Varname string Shorthand string + DefValue string Usage string } var flagsTemplate = `
{{ range . }}
{{ if .Shorthand }}-{{.Shorthand}}, {{ end -}} - --{{.Name}}{{ if .Varname }} <{{.Varname}}>{{ end }}
+ --{{.Name}}{{ if .Varname }} <{{.Varname}}>{{ end }}{{ if not (eq .DefValue "false" "" "[]") }} (Default: {{.DefValue}}){{ end }}
{{.Usage}}
{{ end }}
` @@ -74,6 +75,7 @@ func printFlagsHTML(w io.Writer, fs *pflag.FlagSet) error { Name: f.Name, Varname: varname, Shorthand: f.Shorthand, + DefValue: f.DefValue, Usage: usage, }) }) diff --git a/internal/docs/markdown_test.go b/internal/docs/markdown_test.go index 997029205..86fea360b 100644 --- a/internal/docs/markdown_test.go +++ b/internal/docs/markdown_test.go @@ -103,3 +103,115 @@ func BenchmarkGenMarkdownToFile(b *testing.B) { } } } + +func TestPrintFlagsHTMLShowsDefaultValues(t *testing.T) { + + type TestOptions struct { + Limit int + Template string + Fork bool + NoArchive bool + Topic []string + } + opts := TestOptions{} + + // Int flag should show it + c := &cobra.Command{} + c.Flags().IntVar(&opts.Limit, "limit", 30, "Some limit") + flags := c.NonInheritedFlags() + buf := new(bytes.Buffer) + flags.SetOutput(buf) + + if err := printFlagsHTML(buf, flags); err != nil { + t.Fatalf("printFlagsHTML failed: %s", err.Error()) + } + output := buf.String() + + checkStringContains(t, output, "(Default: 30)") + + // Bool flag should hide it if default is false + c = &cobra.Command{} + c.Flags().BoolVar(&opts.Fork, "fork", false, "Show only forks") + + flags = c.NonInheritedFlags() + buf = new(bytes.Buffer) + flags.SetOutput(buf) + + if err := printFlagsHTML(buf, flags); err != nil { + t.Fatalf("printFlagsHTML failed: %s", err.Error()) + } + output = buf.String() + + checkStringOmits(t, output, "(Default: ") + + // Bool flag should show it if default is true + c = &cobra.Command{} + c.Flags().BoolVar(&opts.NoArchive, "no-archived", true, "Hide archived") + flags = c.NonInheritedFlags() + buf = new(bytes.Buffer) + flags.SetOutput(buf) + + if err := printFlagsHTML(buf, flags); err != nil { + t.Fatalf("printFlagsHTML failed: %s", err.Error()) + } + output = buf.String() + + checkStringContains(t, output, "(Default: true)") + + // String flag should show it if default is not an empty string + c = &cobra.Command{} + c.Flags().StringVar(&opts.Template, "template", "T1", "Some template") + flags = c.NonInheritedFlags() + buf = new(bytes.Buffer) + flags.SetOutput(buf) + + if err := printFlagsHTML(buf, flags); err != nil { + t.Fatalf("printFlagsHTML failed: %s", err.Error()) + } + output = buf.String() + + checkStringContains(t, output, "(Default: T1)") + + // String flag should hide it if default is an empty string + c = &cobra.Command{} + c.Flags().StringVar(&opts.Template, "template", "", "Some template") + + flags = c.NonInheritedFlags() + buf = new(bytes.Buffer) + flags.SetOutput(buf) + + if err := printFlagsHTML(buf, flags); err != nil { + t.Fatalf("printFlagsHTML failed: %s", err.Error()) + } + output = buf.String() + + checkStringOmits(t, output, "(Default: ") + + // String slice flag should hide it if default is an empty slice + c = &cobra.Command{} + c.Flags().StringSliceVar(&opts.Topic, "topic", nil, "Some topics") + flags = c.NonInheritedFlags() + buf = new(bytes.Buffer) + flags.SetOutput(buf) + + if err := printFlagsHTML(buf, flags); err != nil { + t.Fatalf("printFlagsHTML failed: %s", err.Error()) + } + output = buf.String() + + checkStringOmits(t, output, "(Default: ") + + // String slice flag should show it if default is not an empty slice + c = &cobra.Command{} + c.Flags().StringSliceVar(&opts.Topic, "topic", []string{"apples", "oranges"}, "Some topics") + flags = c.NonInheritedFlags() + buf = new(bytes.Buffer) + flags.SetOutput(buf) + + if err := printFlagsHTML(buf, flags); err != nil { + t.Fatalf("printFlagsHTML failed: %s", err.Error()) + } + output = buf.String() + + checkStringContains(t, output, "(Default: [apples,oranges])") +} From 92cb2cc78d61646793b255d714ebd2eeb8c0c5a2 Mon Sep 17 00:00:00 2001 From: Zack Sloane <10229009+zsloane@users.noreply.github.com> Date: Tue, 5 Dec 2023 22:18:14 -0500 Subject: [PATCH 2/6] more closely match cobra default val display --- internal/docs/man.go | 10 +--------- internal/docs/markdown.go | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/internal/docs/man.go b/internal/docs/man.go index 60caa8443..1643fdd98 100644 --- a/internal/docs/man.go +++ b/internal/docs/man.go @@ -150,15 +150,7 @@ func manPrintFlags(buf *bytes.Buffer, flags *pflag.FlagSet) { buf.WriteString(fmt.Sprintf("`--%s`", flag.Name)) } - defval := "" - hiddenDefs := map[string]bool{ - "false": true, - "": true, - "[]": true, - } - if !hiddenDefs[flag.DefValue] { - defval = fmt.Sprintf(" (Default: %s)", flag.Value) - } + defval := getDefaultValueDisplayString(flag) if varname == "" && defval != "" { buf.WriteString(fmt.Sprintf(" `%s`\n", strings.TrimSpace(defval))) diff --git a/internal/docs/markdown.go b/internal/docs/markdown.go index 9c359e99b..6e82aab08 100644 --- a/internal/docs/markdown.go +++ b/internal/docs/markdown.go @@ -46,6 +46,30 @@ func hasNonHelpFlags(fs *pflag.FlagSet) (found bool) { return } +var hiddenFlagDefaults = map[string]bool{ + "false": true, + "": true, + "[]": true, + "duration": true, +} + +var defaultValFormats = map[string]string{ + "string": " (default \"%s\")", +} + +func getDefaultValueDisplayString(f *pflag.Flag) string { + + if hiddenFlagDefaults[f.DefValue] || hiddenFlagDefaults[f.Value.Type()] { + return "" + } + + if dvf, found := defaultValFormats[f.Value.Type()]; found { + return fmt.Sprintf(dvf, f.Value) + } + return fmt.Sprintf(" (default: %s)", f.Value) + +} + type flagView struct { Name string Varname string @@ -56,8 +80,8 @@ type flagView struct { var flagsTemplate = `
{{ range . }} -
{{ if .Shorthand }}-{{.Shorthand}}, {{ end -}} - --{{.Name}}{{ if .Varname }} <{{.Varname}}>{{ end }}{{ if not (eq .DefValue "false" "" "[]") }} (Default: {{.DefValue}}){{ end }}
+
{{ if .Shorthand }}-{{.Shorthand}}, {{ end }} + --{{.Name}}{{ if .Varname }} <{{.Varname}}>{{ end }}{{.DefValue}}
{{.Usage}}
{{ end }}
` @@ -71,11 +95,12 @@ func printFlagsHTML(w io.Writer, fs *pflag.FlagSet) error { return } varname, usage := pflag.UnquoteUsage(f) + flags = append(flags, flagView{ Name: f.Name, Varname: varname, Shorthand: f.Shorthand, - DefValue: f.DefValue, + DefValue: getDefaultValueDisplayString(f), Usage: usage, }) }) From 857cd4904065ef290ff6e58abb6cac5b734814c9 Mon Sep 17 00:00:00 2001 From: Zack Sloane <10229009+zsloane@users.noreply.github.com> Date: Tue, 5 Dec 2023 23:33:01 -0500 Subject: [PATCH 3/6] fix special cases for duration flags --- internal/docs/markdown.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/docs/markdown.go b/internal/docs/markdown.go index 6e82aab08..078113dc3 100644 --- a/internal/docs/markdown.go +++ b/internal/docs/markdown.go @@ -47,14 +47,15 @@ func hasNonHelpFlags(fs *pflag.FlagSet) (found bool) { } var hiddenFlagDefaults = map[string]bool{ - "false": true, - "": true, - "[]": true, - "duration": true, + "false": true, + "": true, + "[]": true, + "0s": true, } var defaultValFormats = map[string]string{ - "string": " (default \"%s\")", + "string": " (default \"%s\")", + "duration": " (default \"%s\")", } func getDefaultValueDisplayString(f *pflag.Flag) string { From b6dadfa7fba20ee68895bcffdd95fc2605cb9e0a Mon Sep 17 00:00:00 2001 From: Zack Sloane <10229009+zsloane@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:23:24 -0500 Subject: [PATCH 4/6] test update, more consistent default value display --- internal/docs/man_test.go | 10 +++++----- internal/docs/markdown.go | 2 +- internal/docs/markdown_test.go | 14 +++++++------- pkg/cmd/config/config.go | 5 ++++- pkg/cmd/gist/create/create.go | 2 +- pkg/cmd/pr/checkout/checkout.go | 2 +- pkg/cmd/pr/create/create.go | 2 +- pkg/cmd/release/create/create.go | 4 ++-- pkg/cmd/release/edit/edit.go | 2 +- pkg/cmd/repo/sync/sync.go | 2 +- 10 files changed, 24 insertions(+), 21 deletions(-) diff --git a/internal/docs/man_test.go b/internal/docs/man_test.go index 80a1326c0..fb595d17d 100644 --- a/internal/docs/man_test.go +++ b/internal/docs/man_test.go @@ -107,7 +107,7 @@ func TestManPrintFlagsHidesShortDeprecated(t *testing.T) { manPrintFlags(buf, c.Flags()) got := buf.String() - expected := "`--foo` ` (Default: default)`\n: Foo flag\n\n" + expected := "`--foo` ` (default \"default\")`\n: Foo flag\n\n" if got != expected { t.Errorf("Expected %q, got %q", expected, got) } @@ -147,7 +147,7 @@ func TestManPrintFlagsShowsDefaultValues(t *testing.T) { manPrintFlags(buf, c.Flags()) got := buf.String() - expected := "`--limit` ` (Default: 30)`\n: Some limit\n\n" + expected := "`--limit` ` (default 30)`\n: Some limit\n\n" if got != expected { t.Errorf("Expected %q, got %q", expected, got) } @@ -173,7 +173,7 @@ func TestManPrintFlagsShowsDefaultValues(t *testing.T) { manPrintFlags(buf, c.Flags()) got = buf.String() - expected = "`--no-archived` `(Default: true)`\n: Hide archived\n\n" + expected = "`--no-archived` `(default true)`\n: Hide archived\n\n" if got != expected { t.Errorf("Expected %q, got %q", expected, got) } @@ -186,7 +186,7 @@ func TestManPrintFlagsShowsDefaultValues(t *testing.T) { manPrintFlags(buf, c.Flags()) got = buf.String() - expected = "`--template` ` (Default: T1)`\n: Some template\n\n" + expected = "`--template` ` (default \"T1\")`\n: Some template\n\n" if got != expected { t.Errorf("Expected %q, got %q", expected, got) } @@ -225,7 +225,7 @@ func TestManPrintFlagsShowsDefaultValues(t *testing.T) { manPrintFlags(buf, c.Flags()) got = buf.String() - expected = "`--topic` ` (Default: [apples,oranges])`\n: Some topics\n\n" + expected = "`--topic` ` (default [apples,oranges])`\n: Some topics\n\n" if got != expected { t.Errorf("Expected %q, got %q", expected, got) } diff --git a/internal/docs/markdown.go b/internal/docs/markdown.go index 078113dc3..8a193d0b6 100644 --- a/internal/docs/markdown.go +++ b/internal/docs/markdown.go @@ -67,7 +67,7 @@ func getDefaultValueDisplayString(f *pflag.Flag) string { if dvf, found := defaultValFormats[f.Value.Type()]; found { return fmt.Sprintf(dvf, f.Value) } - return fmt.Sprintf(" (default: %s)", f.Value) + return fmt.Sprintf(" (default %s)", f.Value) } diff --git a/internal/docs/markdown_test.go b/internal/docs/markdown_test.go index 86fea360b..0bf65ddf3 100644 --- a/internal/docs/markdown_test.go +++ b/internal/docs/markdown_test.go @@ -127,7 +127,7 @@ func TestPrintFlagsHTMLShowsDefaultValues(t *testing.T) { } output := buf.String() - checkStringContains(t, output, "(Default: 30)") + checkStringContains(t, output, "(default 30)") // Bool flag should hide it if default is false c = &cobra.Command{} @@ -142,7 +142,7 @@ func TestPrintFlagsHTMLShowsDefaultValues(t *testing.T) { } output = buf.String() - checkStringOmits(t, output, "(Default: ") + checkStringOmits(t, output, "(default ") // Bool flag should show it if default is true c = &cobra.Command{} @@ -156,7 +156,7 @@ func TestPrintFlagsHTMLShowsDefaultValues(t *testing.T) { } output = buf.String() - checkStringContains(t, output, "(Default: true)") + checkStringContains(t, output, "(default true)") // String flag should show it if default is not an empty string c = &cobra.Command{} @@ -170,7 +170,7 @@ func TestPrintFlagsHTMLShowsDefaultValues(t *testing.T) { } output = buf.String() - checkStringContains(t, output, "(Default: T1)") + checkStringContains(t, output, "(default "T1")") // String flag should hide it if default is an empty string c = &cobra.Command{} @@ -185,7 +185,7 @@ func TestPrintFlagsHTMLShowsDefaultValues(t *testing.T) { } output = buf.String() - checkStringOmits(t, output, "(Default: ") + checkStringOmits(t, output, "(default ") // String slice flag should hide it if default is an empty slice c = &cobra.Command{} @@ -199,7 +199,7 @@ func TestPrintFlagsHTMLShowsDefaultValues(t *testing.T) { } output = buf.String() - checkStringOmits(t, output, "(Default: ") + checkStringOmits(t, output, "(default ") // String slice flag should show it if default is not an empty slice c = &cobra.Command{} @@ -213,5 +213,5 @@ func TestPrintFlagsHTMLShowsDefaultValues(t *testing.T) { } output = buf.String() - checkStringContains(t, output, "(Default: [apples,oranges])") + checkStringContains(t, output, "(default [apples,oranges])") } diff --git a/pkg/cmd/config/config.go b/pkg/cmd/config/config.go index cf374ec1f..03f575073 100644 --- a/pkg/cmd/config/config.go +++ b/pkg/cmd/config/config.go @@ -19,8 +19,11 @@ func NewCmdConfig(f *cmdutil.Factory) *cobra.Command { longDoc.WriteString("Current respected settings:\n") for _, co := range config.ConfigOptions() { longDoc.WriteString(fmt.Sprintf("- %s: %s", co.Key, co.Description)) + if len(co.AllowedValues) > 0 { + longDoc.WriteString(fmt.Sprintf(" {%s}", strings.Join(co.AllowedValues, "|"))) + } if co.DefaultValue != "" { - longDoc.WriteString(fmt.Sprintf(" (default: %q)", co.DefaultValue)) + longDoc.WriteString(fmt.Sprintf(" (default %s)", co.DefaultValue)) } longDoc.WriteRune('\n') } diff --git a/pkg/cmd/gist/create/create.go b/pkg/cmd/gist/create/create.go index 5dec11cb7..ad293419f 100644 --- a/pkg/cmd/gist/create/create.go +++ b/pkg/cmd/gist/create/create.go @@ -96,7 +96,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co cmd.Flags().StringVarP(&opts.Description, "desc", "d", "", "A description for this gist") cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open the web browser with created gist") - cmd.Flags().BoolVarP(&opts.Public, "public", "p", false, "List the gist publicly (default: secret)") + cmd.Flags().BoolVarP(&opts.Public, "public", "p", false, "List the gist publicly (default \"secret\")") cmd.Flags().StringVarP(&opts.FilenameOverride, "filename", "f", "", "Provide a filename to be used when reading from standard input") return cmd } diff --git a/pkg/cmd/pr/checkout/checkout.go b/pkg/cmd/pr/checkout/checkout.go index 389d554be..c28ba166b 100644 --- a/pkg/cmd/pr/checkout/checkout.go +++ b/pkg/cmd/pr/checkout/checkout.go @@ -65,7 +65,7 @@ func NewCmdCheckout(f *cmdutil.Factory, runF func(*CheckoutOptions) error) *cobr cmd.Flags().BoolVarP(&opts.RecurseSubmodules, "recurse-submodules", "", false, "Update all submodules after checkout") cmd.Flags().BoolVarP(&opts.Force, "force", "f", false, "Reset the existing local branch to the latest state of the pull request") cmd.Flags().BoolVarP(&opts.Detach, "detach", "", false, "Checkout PR with a detached HEAD") - cmd.Flags().StringVarP(&opts.BranchName, "branch", "b", "", "Local branch name to use (default: the name of the head branch)") + cmd.Flags().StringVarP(&opts.BranchName, "branch", "b", "", "Local branch name to use (default )") return cmd } diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index 21cb41964..d5a44273b 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -194,7 +194,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co fl.StringVarP(&opts.Body, "body", "b", "", "Body for the pull request") fl.StringVarP(&bodyFile, "body-file", "F", "", "Read body text from `file` (use \"-\" to read from standard input)") fl.StringVarP(&opts.BaseBranch, "base", "B", "", "The `branch` into which you want your code merged") - fl.StringVarP(&opts.HeadBranch, "head", "H", "", "The `branch` that contains commits for your pull request (default: current branch)") + fl.StringVarP(&opts.HeadBranch, "head", "H", "", "The `branch` that contains commits for your pull request (default )") fl.BoolVarP(&opts.WebMode, "web", "w", false, "Open the web browser to create a pull request") fl.BoolVarP(&opts.Autofill, "fill", "f", false, "Use commit info for title and body") fl.BoolVar(&opts.FillFirst, "fill-first", false, "Use first commit info for title and body") diff --git a/pkg/cmd/release/create/create.go b/pkg/cmd/release/create/create.go index 8c8f58a61..7dd269c8b 100644 --- a/pkg/cmd/release/create/create.go +++ b/pkg/cmd/release/create/create.go @@ -178,14 +178,14 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co cmd.Flags().BoolVarP(&opts.Draft, "draft", "d", false, "Save the release as a draft instead of publishing it") cmd.Flags().BoolVarP(&opts.Prerelease, "prerelease", "p", false, "Mark the release as a prerelease") - cmd.Flags().StringVar(&opts.Target, "target", "", "Target `branch` or full commit SHA (default: main branch)") + cmd.Flags().StringVar(&opts.Target, "target", "", "Target `branch` or full commit SHA (default
)") cmd.Flags().StringVarP(&opts.Name, "title", "t", "", "Release title") cmd.Flags().StringVarP(&opts.Body, "notes", "n", "", "Release notes") cmd.Flags().StringVarP(¬esFile, "notes-file", "F", "", "Read release notes from `file` (use \"-\" to read from standard input)") cmd.Flags().StringVarP(&opts.DiscussionCategory, "discussion-category", "", "", "Start a discussion in the specified category") cmd.Flags().BoolVarP(&opts.GenerateNotes, "generate-notes", "", false, "Automatically generate title and notes for the release") cmd.Flags().StringVar(&opts.NotesStartTag, "notes-start-tag", "", "Tag to use as the starting point for generating release notes") - cmdutil.NilBoolFlag(cmd, &opts.IsLatest, "latest", "", "Mark this release as \"Latest\" (default: automatic based on date and version)") + cmdutil.NilBoolFlag(cmd, &opts.IsLatest, "latest", "", "Mark this release as \"Latest\" (default )") cmd.Flags().BoolVarP(&opts.VerifyTag, "verify-tag", "", false, "Abort in case the git tag doesn't already exist in the remote repository") cmd.Flags().BoolVarP(&opts.NotesFromTag, "notes-from-tag", "", false, "Automatically generate notes from annotated tag") diff --git a/pkg/cmd/release/edit/edit.go b/pkg/cmd/release/edit/edit.go index 0360911bf..4078217b8 100644 --- a/pkg/cmd/release/edit/edit.go +++ b/pkg/cmd/release/edit/edit.go @@ -79,7 +79,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman cmdutil.NilStringFlag(cmd, &opts.Body, "notes", "n", "Release notes") cmdutil.NilStringFlag(cmd, &opts.Name, "title", "t", "Release title") cmdutil.NilStringFlag(cmd, &opts.DiscussionCategory, "discussion-category", "", "Start a discussion in the specified category when publishing a draft") - cmd.Flags().StringVar(&opts.Target, "target", "", "Target `branch` or full commit SHA (default: main branch)") + cmd.Flags().StringVar(&opts.Target, "target", "", "Target `branch` or full commit SHA (default
)") cmd.Flags().StringVar(&opts.TagName, "tag", "", "The name of the tag") cmd.Flags().StringVarP(¬esFile, "notes-file", "F", "", "Read release notes from `file` (use \"-\" to read from standard input)") cmd.Flags().BoolVar(&opts.VerifyTag, "verify-tag", false, "Abort in case the git tag doesn't already exist in the remote repository") diff --git a/pkg/cmd/repo/sync/sync.go b/pkg/cmd/repo/sync/sync.go index 94be50bbf..1a410a9ad 100644 --- a/pkg/cmd/repo/sync/sync.go +++ b/pkg/cmd/repo/sync/sync.go @@ -83,7 +83,7 @@ func NewCmdSync(f *cmdutil.Factory, runF func(*SyncOptions) error) *cobra.Comman } cmd.Flags().StringVarP(&opts.SrcArg, "source", "s", "", "Source repository") - cmd.Flags().StringVarP(&opts.Branch, "branch", "b", "", "Branch to sync (default: default branch)") + cmd.Flags().StringVarP(&opts.Branch, "branch", "b", "", "Branch to sync (default )") cmd.Flags().BoolVarP(&opts.Force, "force", "", false, "Hard reset the branch of the destination repository to match the source repository") return cmd } From d5f57325460ae02874db80ceb11029a1e668f8f0 Mon Sep 17 00:00:00 2001 From: Zack Sloane <10229009+zsloane@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:26:48 -0500 Subject: [PATCH 5/6] Update pkg/cmd/config/config.go Co-authored-by: Andy Feller --- pkg/cmd/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/config/config.go b/pkg/cmd/config/config.go index 03f575073..20a660279 100644 --- a/pkg/cmd/config/config.go +++ b/pkg/cmd/config/config.go @@ -18,7 +18,7 @@ func NewCmdConfig(f *cmdutil.Factory) *cobra.Command { longDoc.WriteString("Display or change configuration settings for gh.\n\n") longDoc.WriteString("Current respected settings:\n") for _, co := range config.ConfigOptions() { - longDoc.WriteString(fmt.Sprintf("- %s: %s", co.Key, co.Description)) + longDoc.WriteString(fmt.Sprintf("- `%s`: %s", co.Key, co.Description)) if len(co.AllowedValues) > 0 { longDoc.WriteString(fmt.Sprintf(" {%s}", strings.Join(co.AllowedValues, "|"))) } From f70bcba7797a2c92d6860ac2b94ddecf91d0fb0d Mon Sep 17 00:00:00 2001 From: Zack Sloane <10229009+zsloane@users.noreply.github.com> Date: Thu, 1 Feb 2024 21:35:31 +0000 Subject: [PATCH 6/6] switch to [] characters for default info in usage strings --- pkg/cmd/pr/checkout/checkout.go | 2 +- pkg/cmd/pr/create/create.go | 2 +- pkg/cmd/release/create/create.go | 4 ++-- pkg/cmd/release/edit/edit.go | 2 +- pkg/cmd/repo/sync/sync.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/pr/checkout/checkout.go b/pkg/cmd/pr/checkout/checkout.go index c28ba166b..269c8aaab 100644 --- a/pkg/cmd/pr/checkout/checkout.go +++ b/pkg/cmd/pr/checkout/checkout.go @@ -65,7 +65,7 @@ func NewCmdCheckout(f *cmdutil.Factory, runF func(*CheckoutOptions) error) *cobr cmd.Flags().BoolVarP(&opts.RecurseSubmodules, "recurse-submodules", "", false, "Update all submodules after checkout") cmd.Flags().BoolVarP(&opts.Force, "force", "f", false, "Reset the existing local branch to the latest state of the pull request") cmd.Flags().BoolVarP(&opts.Detach, "detach", "", false, "Checkout PR with a detached HEAD") - cmd.Flags().StringVarP(&opts.BranchName, "branch", "b", "", "Local branch name to use (default )") + cmd.Flags().StringVarP(&opts.BranchName, "branch", "b", "", "Local branch name to use (default [the name of the head branch])") return cmd } diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index 710a90364..a1d679869 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -203,7 +203,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co fl.StringVarP(&opts.Body, "body", "b", "", "Body for the pull request") fl.StringVarP(&bodyFile, "body-file", "F", "", "Read body text from `file` (use \"-\" to read from standard input)") fl.StringVarP(&opts.BaseBranch, "base", "B", "", "The `branch` into which you want your code merged") - fl.StringVarP(&opts.HeadBranch, "head", "H", "", "The `branch` that contains commits for your pull request (default )") + fl.StringVarP(&opts.HeadBranch, "head", "H", "", "The `branch` that contains commits for your pull request (default [current branch])") fl.BoolVarP(&opts.WebMode, "web", "w", false, "Open the web browser to create a pull request") fl.BoolVarP(&opts.FillVerbose, "fill-verbose", "", false, "Use commits msg+body for description") fl.BoolVarP(&opts.Autofill, "fill", "f", false, "Use commit info for title and body") diff --git a/pkg/cmd/release/create/create.go b/pkg/cmd/release/create/create.go index 7dd269c8b..f575a339a 100644 --- a/pkg/cmd/release/create/create.go +++ b/pkg/cmd/release/create/create.go @@ -178,14 +178,14 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co cmd.Flags().BoolVarP(&opts.Draft, "draft", "d", false, "Save the release as a draft instead of publishing it") cmd.Flags().BoolVarP(&opts.Prerelease, "prerelease", "p", false, "Mark the release as a prerelease") - cmd.Flags().StringVar(&opts.Target, "target", "", "Target `branch` or full commit SHA (default
)") + cmd.Flags().StringVar(&opts.Target, "target", "", "Target `branch` or full commit SHA (default [main branch])") cmd.Flags().StringVarP(&opts.Name, "title", "t", "", "Release title") cmd.Flags().StringVarP(&opts.Body, "notes", "n", "", "Release notes") cmd.Flags().StringVarP(¬esFile, "notes-file", "F", "", "Read release notes from `file` (use \"-\" to read from standard input)") cmd.Flags().StringVarP(&opts.DiscussionCategory, "discussion-category", "", "", "Start a discussion in the specified category") cmd.Flags().BoolVarP(&opts.GenerateNotes, "generate-notes", "", false, "Automatically generate title and notes for the release") cmd.Flags().StringVar(&opts.NotesStartTag, "notes-start-tag", "", "Tag to use as the starting point for generating release notes") - cmdutil.NilBoolFlag(cmd, &opts.IsLatest, "latest", "", "Mark this release as \"Latest\" (default )") + cmdutil.NilBoolFlag(cmd, &opts.IsLatest, "latest", "", "Mark this release as \"Latest\" (default [automatic based on date and version])") cmd.Flags().BoolVarP(&opts.VerifyTag, "verify-tag", "", false, "Abort in case the git tag doesn't already exist in the remote repository") cmd.Flags().BoolVarP(&opts.NotesFromTag, "notes-from-tag", "", false, "Automatically generate notes from annotated tag") diff --git a/pkg/cmd/release/edit/edit.go b/pkg/cmd/release/edit/edit.go index 4078217b8..245041bae 100644 --- a/pkg/cmd/release/edit/edit.go +++ b/pkg/cmd/release/edit/edit.go @@ -79,7 +79,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman cmdutil.NilStringFlag(cmd, &opts.Body, "notes", "n", "Release notes") cmdutil.NilStringFlag(cmd, &opts.Name, "title", "t", "Release title") cmdutil.NilStringFlag(cmd, &opts.DiscussionCategory, "discussion-category", "", "Start a discussion in the specified category when publishing a draft") - cmd.Flags().StringVar(&opts.Target, "target", "", "Target `branch` or full commit SHA (default
)") + cmd.Flags().StringVar(&opts.Target, "target", "", "Target `branch` or full commit SHA (default [main branch])") cmd.Flags().StringVar(&opts.TagName, "tag", "", "The name of the tag") cmd.Flags().StringVarP(¬esFile, "notes-file", "F", "", "Read release notes from `file` (use \"-\" to read from standard input)") cmd.Flags().BoolVar(&opts.VerifyTag, "verify-tag", false, "Abort in case the git tag doesn't already exist in the remote repository") diff --git a/pkg/cmd/repo/sync/sync.go b/pkg/cmd/repo/sync/sync.go index 1a410a9ad..87badc7a1 100644 --- a/pkg/cmd/repo/sync/sync.go +++ b/pkg/cmd/repo/sync/sync.go @@ -83,7 +83,7 @@ func NewCmdSync(f *cmdutil.Factory, runF func(*SyncOptions) error) *cobra.Comman } cmd.Flags().StringVarP(&opts.SrcArg, "source", "s", "", "Source repository") - cmd.Flags().StringVarP(&opts.Branch, "branch", "b", "", "Branch to sync (default )") + cmd.Flags().StringVarP(&opts.Branch, "branch", "b", "", "Branch to sync (default [default branch])") cmd.Flags().BoolVarP(&opts.Force, "force", "", false, "Hard reset the branch of the destination repository to match the source repository") return cmd }