From 0dfc0f733fcc0e3b1b8e8a5a91d5b2aa3515fac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 11 Jun 2020 20:31:37 +0200 Subject: [PATCH] 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. --- command/alias.go | 5 +++-- command/credits.go | 5 +++-- command/gist.go | 5 +++-- command/help.go | 7 +++---- command/issue.go | 5 +++-- command/pr.go | 9 +++++---- command/pr_review.go | 5 +++-- command/repo.go | 13 +++++++------ command/root.go | 5 +++-- go.mod | 1 + go.sum | 2 ++ 11 files changed, 36 insertions(+), 26 deletions(-) diff --git a/command/alias.go b/command/alias.go index 985664768..64056f9d5 100644 --- a/command/alias.go +++ b/command/alias.go @@ -5,6 +5,7 @@ import ( "sort" "strings" + "github.com/MakeNowJust/heredoc" "github.com/cli/cli/utils" "github.com/google/shlex" "github.com/spf13/cobra" @@ -30,7 +31,7 @@ var aliasSetCmd = &cobra.Command{ The expansion may specify additional arguments and flags. If the expansion includes positional placeholders such as '$1', '$2', etc., any extra arguments that follow the invocation of an alias will be inserted appropriately.`, - Example: ` + Example: heredoc.Doc(` $ gh alias set pv 'pr view' $ gh pv -w 123 #=> gh pr view -w 123 @@ -40,7 +41,7 @@ that follow the invocation of an alias will be inserted appropriately.`, $ gh alias set epicsBy 'issue list --author="$1" --label="epic"' $ gh epicsBy vilmibm #=> gh issue list --author="vilmibm" --label="epic" -`, + `), Args: cobra.MinimumNArgs(2), RunE: aliasSet, diff --git a/command/credits.go b/command/credits.go index f64bbb3df..0104edb02 100644 --- a/command/credits.go +++ b/command/credits.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/MakeNowJust/heredoc" "github.com/spf13/cobra" "golang.org/x/crypto/ssh/terminal" @@ -44,7 +45,7 @@ var creditsCmd = &cobra.Command{ Use: "credits", Short: "View credits for this tool", Long: `View animated credits for gh, the tool you are currently using :)`, - Example: ` + Example: heredoc.Doc(` # see a credits animation for this project $ gh credits @@ -53,7 +54,7 @@ var creditsCmd = &cobra.Command{ # just print the contributors, one per line $ gh credits | cat -`, + `), Args: cobra.ExactArgs(0), RunE: ghCredits, Hidden: true, diff --git a/command/gist.go b/command/gist.go index 765ffc765..227f8bd92 100644 --- a/command/gist.go +++ b/command/gist.go @@ -8,6 +8,7 @@ import ( "os" "path" + "github.com/MakeNowJust/heredoc" "github.com/cli/cli/api" "github.com/cli/cli/utils" "github.com/spf13/cobra" @@ -35,7 +36,7 @@ Gists can be created from one or multiple files. Alternatively, pass "-" as file name to read from standard input. By default, gists are private; use '--public' to make publicly listed ones.`, - Example: ` + Example: heredoc.Doc(` # publish file 'hello.py' as a public gist $ gh gist create --public hello.py @@ -50,7 +51,7 @@ By default, gists are private; use '--public' to make publicly listed ones.`, # create a gist from output piped from another command $ cat cool.txt | gh gist create -`, + `), RunE: gistCreate, } diff --git a/command/help.go b/command/help.go index 7f08071de..d93e779de 100644 --- a/command/help.go +++ b/command/help.go @@ -2,6 +2,7 @@ package command import ( "fmt" + "regexp" "strings" "github.com/cli/cli/utils" @@ -78,7 +79,8 @@ func rootHelpFunc(command *cobra.Command, args []string) { if len(additionalCommands) > 0 { helpEntries = append(helpEntries, helpEntry{"ADDITIONAL COMMANDS", strings.Join(additionalCommands, "\n")}) } - flagUsages := strings.TrimRight(command.LocalFlags().FlagUsages(), "\n") + dedent := regexp.MustCompile(`(?m)^ `) + flagUsages := dedent.ReplaceAllString(command.LocalFlags().FlagUsages(), "") if flagUsages != "" { helpEntries = append(helpEntries, helpEntry{"FLAGS", flagUsages}) } @@ -102,9 +104,6 @@ Read the manual at http://cli.github.com/manual`}) fmt.Fprintln(out, utils.Bold(e.Title)) for _, l := range strings.Split(strings.Trim(e.Body, "\n\r"), "\n") { - if e.Title == "EXAMPLES" { - l = strings.TrimPrefix(l, "\t") - } fmt.Fprintln(out, " "+l) } } else { diff --git a/command/issue.go b/command/issue.go index e2a4cfe32..8a68e2652 100644 --- a/command/issue.go +++ b/command/issue.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "github.com/MakeNowJust/heredoc" "github.com/cli/cli/api" "github.com/cli/cli/git" "github.com/cli/cli/internal/ghrepo" @@ -52,11 +53,11 @@ var issueCmd = &cobra.Command{ Use: "issue ", Short: "Create and view issues", Long: `Work with GitHub issues`, - Example: ` + Example: heredoc.Doc(` $ gh issue list $ gh issue create --label bug $ gh issue view --web -`, + `), Annotations: map[string]string{ "IsCore": "true", "help:arguments": `An issue can be supplied as argument in any of the following formats: diff --git a/command/pr.go b/command/pr.go index 89828d866..adf8347ab 100644 --- a/command/pr.go +++ b/command/pr.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" + "github.com/MakeNowJust/heredoc" "github.com/cli/cli/api" "github.com/cli/cli/context" "github.com/cli/cli/git" @@ -49,11 +50,11 @@ var prCmd = &cobra.Command{ Use: "pr ", Short: "Create, view, and checkout pull requests", Long: `Work with GitHub pull requests`, - Example: ` + Example: heredoc.Doc(` $ gh pr checkout 353 $ gh pr create --fill $ gh pr view --web -`, + `), Annotations: map[string]string{ "IsCore": "true", "help:arguments": `A pull request can be supplied as argument in any of the following formats: @@ -64,11 +65,11 @@ var prCmd = &cobra.Command{ var prListCmd = &cobra.Command{ Use: "list", Short: "List and filter pull requests in this repository", - Example: ` + Example: heredoc.Doc(` $ gh pr list --limit 999 $ gh pr list --state closed $ gh pr list --label "priority 1" --label "bug" -`, + `), RunE: prList, } var prStatusCmd = &cobra.Command{ diff --git a/command/pr_review.go b/command/pr_review.go index f93eaad81..08efc638d 100644 --- a/command/pr_review.go +++ b/command/pr_review.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/AlecAivazis/survey/v2" + "github.com/MakeNowJust/heredoc" "github.com/spf13/cobra" "github.com/cli/cli/api" @@ -27,7 +28,7 @@ var prReviewCmd = &cobra.Command{ Long: `Add a review to a pull request. Without an argument, the pull request that belongs to the current branch is reviewed.`, - Example: ` + Example: heredoc.Doc(` # approve the pull request of the current branch $ gh pr review --approve @@ -39,7 +40,7 @@ Without an argument, the pull request that belongs to the current branch is revi # request changes on a specific pull request $ gh pr review 123 -r -b "needs more ASCII art" -`, + `), Args: cobra.MaximumNArgs(1), RunE: prReview, } diff --git a/command/repo.go b/command/repo.go index ab6c1322f..7c15945aa 100644 --- a/command/repo.go +++ b/command/repo.go @@ -10,6 +10,7 @@ import ( "time" "github.com/AlecAivazis/survey/v2" + "github.com/MakeNowJust/heredoc" "github.com/cli/cli/api" "github.com/cli/cli/git" "github.com/cli/cli/internal/ghrepo" @@ -47,11 +48,11 @@ var repoCmd = &cobra.Command{ Use: "repo ", Short: "Create, clone, fork, and view repositories", Long: `Work with GitHub repositories`, - Example: ` + Example: heredoc.Doc(` $ gh repo create $ gh repo clone cli/cli $ gh repo view --web -`, + `), Annotations: map[string]string{ "IsCore": "true", "help:arguments": ` @@ -77,7 +78,7 @@ var repoCreateCmd = &cobra.Command{ Use: "create []", Short: "Create a new repository", Long: `Create a new GitHub repository.`, - Example: ` + Example: heredoc.Doc(` # create a repository under your account using the current directory name $ gh repo create @@ -86,7 +87,7 @@ var repoCreateCmd = &cobra.Command{ # create a repository in an organization $ gh repo create cli/my-project -`, + `), Annotations: map[string]string{"help:arguments": `A repository can be supplied as an argument in any of the following formats: - - by URL, e.g. "https://github.com/OWNER/REPO"`}, @@ -116,7 +117,7 @@ With '--web', open the repository in a web browser instead.`, var repoCreditsCmd = &cobra.Command{ Use: "credits []", Short: "View credits for a repository", - Example: ` + Example: heredoc.Doc(` # view credits for the current repository $ gh repo credits @@ -128,7 +129,7 @@ var repoCreditsCmd = &cobra.Command{ # pipe to just print the contributors, one per line $ gh repo credits | cat -`, + `), Args: cobra.MaximumNArgs(1), RunE: repoCredits, Hidden: true, diff --git a/command/root.go b/command/root.go index ca30e57a8..92a25e67f 100644 --- a/command/root.go +++ b/command/root.go @@ -10,6 +10,7 @@ import ( "runtime/debug" "strings" + "github.com/MakeNowJust/heredoc" "github.com/cli/cli/api" "github.com/cli/cli/context" "github.com/cli/cli/internal/config" @@ -96,11 +97,11 @@ var RootCmd = &cobra.Command{ SilenceErrors: true, SilenceUsage: true, - Example: ` + Example: heredoc.Doc(` $ gh issue create $ gh repo clone cli/cli $ gh pr checkout 321 -`, + `), Annotations: map[string]string{ "help:feedback": ` Fill out our feedback form https://forms.gle/umxd3h31c7aMQFKG7 diff --git a/go.mod b/go.mod index 7f1484a03..6857e1947 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.13 require ( github.com/AlecAivazis/survey/v2 v2.0.7 + github.com/MakeNowJust/heredoc v1.0.0 github.com/briandowns/spinner v1.11.1 github.com/charmbracelet/glamour v0.1.1-0.20200320173916-301d3bcf3058 github.com/dlclark/regexp2 v1.2.0 // indirect diff --git a/go.sum b/go.sum index d0d7585bf..42f30698a 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/AlecAivazis/survey/v2 v2.0.7 h1:+f825XHLse/hWd2tE/V5df04WFGimk34Eyg/z github.com/AlecAivazis/survey/v2 v2.0.7/go.mod h1:mlizQTaPjnR4jcpwRSaSlkbsRfYFEyKgLQvYTzxxiHA= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= +github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=