Skip to content

Commit 0dfc0f7

Browse files
committed
Fix indentation of Example blocks
In HTML, `Example` blocks seem to be already injected in fenced Markdown blocks `` ``` ``, so they don't need to be especially intented.
1 parent 99fce24 commit 0dfc0f7

File tree

11 files changed

+36
-26
lines changed

11 files changed

+36
-26
lines changed

command/alias.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"sort"
66
"strings"
77

8+
"github.com/MakeNowJust/heredoc"
89
"github.com/cli/cli/utils"
910
"github.com/google/shlex"
1011
"github.com/spf13/cobra"
@@ -30,7 +31,7 @@ var aliasSetCmd = &cobra.Command{
3031
The expansion may specify additional arguments and flags. If the expansion
3132
includes positional placeholders such as '$1', '$2', etc., any extra arguments
3233
that follow the invocation of an alias will be inserted appropriately.`,
33-
Example: `
34+
Example: heredoc.Doc(`
3435
$ gh alias set pv 'pr view'
3536
$ gh pv -w 123
3637
#=> gh pr view -w 123
@@ -40,7 +41,7 @@ that follow the invocation of an alias will be inserted appropriately.`,
4041
$ gh alias set epicsBy 'issue list --author="$1" --label="epic"'
4142
$ gh epicsBy vilmibm
4243
#=> gh issue list --author="vilmibm" --label="epic"
43-
`,
44+
`),
4445
Args: cobra.MinimumNArgs(2),
4546
RunE: aliasSet,
4647

command/credits.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"time"
1313

14+
"github.com/MakeNowJust/heredoc"
1415
"github.com/spf13/cobra"
1516
"golang.org/x/crypto/ssh/terminal"
1617

@@ -44,7 +45,7 @@ var creditsCmd = &cobra.Command{
4445
Use: "credits",
4546
Short: "View credits for this tool",
4647
Long: `View animated credits for gh, the tool you are currently using :)`,
47-
Example: `
48+
Example: heredoc.Doc(`
4849
# see a credits animation for this project
4950
$ gh credits
5051
@@ -53,7 +54,7 @@ var creditsCmd = &cobra.Command{
5354
5455
# just print the contributors, one per line
5556
$ gh credits | cat
56-
`,
57+
`),
5758
Args: cobra.ExactArgs(0),
5859
RunE: ghCredits,
5960
Hidden: true,

command/gist.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path"
1010

11+
"github.com/MakeNowJust/heredoc"
1112
"github.com/cli/cli/api"
1213
"github.com/cli/cli/utils"
1314
"github.com/spf13/cobra"
@@ -35,7 +36,7 @@ Gists can be created from one or multiple files. Alternatively, pass "-" as
3536
file name to read from standard input.
3637
3738
By default, gists are private; use '--public' to make publicly listed ones.`,
38-
Example: `
39+
Example: heredoc.Doc(`
3940
# publish file 'hello.py' as a public gist
4041
$ gh gist create --public hello.py
4142
@@ -50,7 +51,7 @@ By default, gists are private; use '--public' to make publicly listed ones.`,
5051
5152
# create a gist from output piped from another command
5253
$ cat cool.txt | gh gist create
53-
`,
54+
`),
5455
RunE: gistCreate,
5556
}
5657

command/help.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package command
22

33
import (
44
"fmt"
5+
"regexp"
56
"strings"
67

78
"github.com/cli/cli/utils"
@@ -78,7 +79,8 @@ func rootHelpFunc(command *cobra.Command, args []string) {
7879
if len(additionalCommands) > 0 {
7980
helpEntries = append(helpEntries, helpEntry{"ADDITIONAL COMMANDS", strings.Join(additionalCommands, "\n")})
8081
}
81-
flagUsages := strings.TrimRight(command.LocalFlags().FlagUsages(), "\n")
82+
dedent := regexp.MustCompile(`(?m)^ `)
83+
flagUsages := dedent.ReplaceAllString(command.LocalFlags().FlagUsages(), "")
8284
if flagUsages != "" {
8385
helpEntries = append(helpEntries, helpEntry{"FLAGS", flagUsages})
8486
}
@@ -102,9 +104,6 @@ Read the manual at http://cli.github.com/manual`})
102104
fmt.Fprintln(out, utils.Bold(e.Title))
103105

104106
for _, l := range strings.Split(strings.Trim(e.Body, "\n\r"), "\n") {
105-
if e.Title == "EXAMPLES" {
106-
l = strings.TrimPrefix(l, "\t")
107-
}
108107
fmt.Fprintln(out, " "+l)
109108
}
110109
} else {

command/issue.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/MakeNowJust/heredoc"
1314
"github.com/cli/cli/api"
1415
"github.com/cli/cli/git"
1516
"github.com/cli/cli/internal/ghrepo"
@@ -52,11 +53,11 @@ var issueCmd = &cobra.Command{
5253
Use: "issue <command>",
5354
Short: "Create and view issues",
5455
Long: `Work with GitHub issues`,
55-
Example: `
56+
Example: heredoc.Doc(`
5657
$ gh issue list
5758
$ gh issue create --label bug
5859
$ gh issue view --web
59-
`,
60+
`),
6061
Annotations: map[string]string{
6162
"IsCore": "true",
6263
"help:arguments": `An issue can be supplied as argument in any of the following formats:

command/pr.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"github.com/AlecAivazis/survey/v2"
13+
"github.com/MakeNowJust/heredoc"
1314
"github.com/cli/cli/api"
1415
"github.com/cli/cli/context"
1516
"github.com/cli/cli/git"
@@ -49,11 +50,11 @@ var prCmd = &cobra.Command{
4950
Use: "pr <command>",
5051
Short: "Create, view, and checkout pull requests",
5152
Long: `Work with GitHub pull requests`,
52-
Example: `
53+
Example: heredoc.Doc(`
5354
$ gh pr checkout 353
5455
$ gh pr create --fill
5556
$ gh pr view --web
56-
`,
57+
`),
5758
Annotations: map[string]string{
5859
"IsCore": "true",
5960
"help:arguments": `A pull request can be supplied as argument in any of the following formats:
@@ -64,11 +65,11 @@ var prCmd = &cobra.Command{
6465
var prListCmd = &cobra.Command{
6566
Use: "list",
6667
Short: "List and filter pull requests in this repository",
67-
Example: `
68+
Example: heredoc.Doc(`
6869
$ gh pr list --limit 999
6970
$ gh pr list --state closed
7071
$ gh pr list --label "priority 1" --label "bug"
71-
`,
72+
`),
7273
RunE: prList,
7374
}
7475
var prStatusCmd = &cobra.Command{

command/pr_review.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/AlecAivazis/survey/v2"
8+
"github.com/MakeNowJust/heredoc"
89
"github.com/spf13/cobra"
910

1011
"github.com/cli/cli/api"
@@ -27,7 +28,7 @@ var prReviewCmd = &cobra.Command{
2728
Long: `Add a review to a pull request.
2829
2930
Without an argument, the pull request that belongs to the current branch is reviewed.`,
30-
Example: `
31+
Example: heredoc.Doc(`
3132
# approve the pull request of the current branch
3233
$ gh pr review --approve
3334
@@ -39,7 +40,7 @@ Without an argument, the pull request that belongs to the current branch is revi
3940
4041
# request changes on a specific pull request
4142
$ gh pr review 123 -r -b "needs more ASCII art"
42-
`,
43+
`),
4344
Args: cobra.MaximumNArgs(1),
4445
RunE: prReview,
4546
}

command/repo.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/AlecAivazis/survey/v2"
13+
"github.com/MakeNowJust/heredoc"
1314
"github.com/cli/cli/api"
1415
"github.com/cli/cli/git"
1516
"github.com/cli/cli/internal/ghrepo"
@@ -47,11 +48,11 @@ var repoCmd = &cobra.Command{
4748
Use: "repo <command>",
4849
Short: "Create, clone, fork, and view repositories",
4950
Long: `Work with GitHub repositories`,
50-
Example: `
51+
Example: heredoc.Doc(`
5152
$ gh repo create
5253
$ gh repo clone cli/cli
5354
$ gh repo view --web
54-
`,
55+
`),
5556
Annotations: map[string]string{
5657
"IsCore": "true",
5758
"help:arguments": `
@@ -77,7 +78,7 @@ var repoCreateCmd = &cobra.Command{
7778
Use: "create [<name>]",
7879
Short: "Create a new repository",
7980
Long: `Create a new GitHub repository.`,
80-
Example: `
81+
Example: heredoc.Doc(`
8182
# create a repository under your account using the current directory name
8283
$ gh repo create
8384
@@ -86,7 +87,7 @@ var repoCreateCmd = &cobra.Command{
8687
8788
# create a repository in an organization
8889
$ gh repo create cli/my-project
89-
`,
90+
`),
9091
Annotations: map[string]string{"help:arguments": `A repository can be supplied as an argument in any of the following formats:
9192
- <OWNER/REPO>
9293
- by URL, e.g. "https://github.com/OWNER/REPO"`},
@@ -116,7 +117,7 @@ With '--web', open the repository in a web browser instead.`,
116117
var repoCreditsCmd = &cobra.Command{
117118
Use: "credits [<repository>]",
118119
Short: "View credits for a repository",
119-
Example: `
120+
Example: heredoc.Doc(`
120121
# view credits for the current repository
121122
$ gh repo credits
122123
@@ -128,7 +129,7 @@ var repoCreditsCmd = &cobra.Command{
128129
129130
# pipe to just print the contributors, one per line
130131
$ gh repo credits | cat
131-
`,
132+
`),
132133
Args: cobra.MaximumNArgs(1),
133134
RunE: repoCredits,
134135
Hidden: true,

command/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"runtime/debug"
1111
"strings"
1212

13+
"github.com/MakeNowJust/heredoc"
1314
"github.com/cli/cli/api"
1415
"github.com/cli/cli/context"
1516
"github.com/cli/cli/internal/config"
@@ -96,11 +97,11 @@ var RootCmd = &cobra.Command{
9697

9798
SilenceErrors: true,
9899
SilenceUsage: true,
99-
Example: `
100+
Example: heredoc.Doc(`
100101
$ gh issue create
101102
$ gh repo clone cli/cli
102103
$ gh pr checkout 321
103-
`,
104+
`),
104105
Annotations: map[string]string{
105106
"help:feedback": `
106107
Fill out our feedback form https://forms.gle/umxd3h31c7aMQFKG7

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.13
44

55
require (
66
github.com/AlecAivazis/survey/v2 v2.0.7
7+
github.com/MakeNowJust/heredoc v1.0.0
78
github.com/briandowns/spinner v1.11.1
89
github.com/charmbracelet/glamour v0.1.1-0.20200320173916-301d3bcf3058
910
github.com/dlclark/regexp2 v1.2.0 // indirect

0 commit comments

Comments
 (0)