diff --git a/commands/issue.go b/commands/issue.go index a42e0d729af752ddc35500116afe6e0f7812cc00..f6baf3027fc32948f19b005670002f7f794f7c67 100644 --- a/commands/issue.go +++ b/commands/issue.go @@ -105,6 +105,10 @@ With no arguments, show a list of open issues. %uI: updated date, ISO 8601 format + %n: newline + + %%: a literal % + -m, --message= The text up to the first blank line in is treated as the issue title, and the rest is used as issue description in Markdown format. @@ -294,7 +298,7 @@ func listIssues(cmd *Command, args *Args) { colorize := ui.IsTerminal(os.Stdout) for _, issue := range issues { - ui.Printf(formatIssue(issue, flagIssueFormat, colorize)) + ui.Print(formatIssue(issue, flagIssueFormat, colorize)) } } @@ -451,7 +455,7 @@ func showIssue(cmd *Command, args *Args) { colorize := ui.IsTerminal(os.Stdout) if flagShowIssueFormat != "" { - ui.Printf(formatIssue(*issue, flagShowIssueFormat, colorize)) + ui.Print(formatIssue(*issue, flagShowIssueFormat, colorize)) return } @@ -581,7 +585,7 @@ func listLabels(cmd *Command, args *Args) { utils.Check(err) for _, label := range labels { - ui.Printf(formatLabel(label, flagLabelsColorize)) + ui.Print(formatLabel(label, flagLabelsColorize)) } } diff --git a/commands/pr.go b/commands/pr.go index fca7950756c343b0dbd5b074791de70325903cff..c31d4a0186b5ad24b4e674c8bae3a6dc1ec6e078 100644 --- a/commands/pr.go +++ b/commands/pr.go @@ -113,6 +113,10 @@ pr checkout [] %mI: merged date, ISO 8601 format + %n: newline + + %%: a literal % + -o, --sort= Sort displayed issues by "created" (default), "updated", "popularity", or "long-running". @@ -216,7 +220,7 @@ func listPulls(cmd *Command, args *Args) { colorize := ui.IsTerminal(os.Stdout) for _, pr := range pulls { - ui.Printf(formatPullRequest(pr, flagPullRequestFormat, colorize)) + ui.Print(formatPullRequest(pr, flagPullRequestFormat, colorize)) } } diff --git a/commands/release.go b/commands/release.go index a88071b9f60e89822bae67a1887b51a577f0655e..894e47423b74049255ecf688a1c68f6454bfec2e 100644 --- a/commands/release.go +++ b/commands/release.go @@ -136,6 +136,10 @@ With '--exclude-prereleases', exclude non-stable releases from the listing. %pI: published date, ISO 8601 format + %n: newline + + %%: a literal % + The git tag name for this release. @@ -246,7 +250,7 @@ func listReleases(cmd *Command, args *Args) { colorize := ui.IsTerminal(os.Stdout) for _, release := range releases { - ui.Printf(formatRelease(release, flagReleaseFormat, colorize)) + ui.Print(formatRelease(release, flagReleaseFormat, colorize)) } } @@ -334,7 +338,7 @@ func showRelease(cmd *Command, args *Args) { colorize := ui.IsTerminal(os.Stdout) if flagShowReleaseFormat != "" { - ui.Printf(formatRelease(*release, flagShowReleaseFormat, colorize)) + ui.Print(formatRelease(*release, flagShowReleaseFormat, colorize)) return } diff --git a/features/issue.feature b/features/issue.feature index d0ae7ca2ac587d9473c58e725ef7464669e574a7..3306b7897adbc8cae3cc4dff940d4b71e2aae697 100644 --- a/features/issue.feature +++ b/features/issue.feature @@ -614,6 +614,26 @@ Feature: hub issue I want this feature\n """ + Scenario: Format with literal % characters + Given the GitHub API server: + """ + get('/repos/github/hub/issues/102') { + json \ + :number => 102, + :state => "open", + :title => "Feature request % hub", + :user => { :login => "alexfornuto" } + } + get('/repos/github/hub/issues/102/comments') { + json [] + } + """ + When I successfully run `hub issue show 102 --format='%t%%t%%n%n'` + Then the output should contain exactly: + """ + Feature request % hub%t%n\n + """ + Scenario: Did not supply an issue number When I run `hub issue show` Then the exit status should be 1 diff --git a/ui/ui.go b/ui/ui.go index 1d8bb4dc7d0fe69b4d52697e9a8a8e66742bc307..37167269e62162e68eced591cfbeef658c60006d 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -10,6 +10,7 @@ import ( ) type UI interface { + Print(a ...interface{}) (n int, err error) Printf(format string, a ...interface{}) (n int, err error) Println(a ...interface{}) (n int, err error) Errorf(format string, a ...interface{}) (n int, err error) @@ -22,6 +23,10 @@ var ( Default UI = Console{Stdout: Stdout, Stderr: Stderr} ) +func Print(a ...interface{}) (n int, err error) { + return Default.Print(a...) +} + func Printf(format string, a ...interface{}) (n int, err error) { return Default.Printf(format, a...) } @@ -47,6 +52,10 @@ type Console struct { Stderr io.Writer } +func (c Console) Print(a ...interface{}) (n int, err error) { + return fmt.Fprint(c.Stdout, a...) +} + func (c Console) Printf(format string, a ...interface{}) (n int, err error) { return fmt.Fprintf(c.Stdout, format, a...) }