зеркало из https://github.com/mislav/hub.git
Don't choke on literal `%` output from `--format` use
In general, avoid using Printf without a static format string.
This commit is contained in:
Родитель
3e6fcc1f8a
Коммит
f8feb335bc
|
@ -298,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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -455,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
|
||||
}
|
||||
|
||||
|
@ -585,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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -220,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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -250,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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
9
ui/ui.go
9
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...)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче