add --quiet global option

This commit is contained in:
Cory Bennett
2017-09-04 18:12:32 -07:00
parent c0358eb67c
commit c226077320
23 changed files with 97 additions and 46 deletions
+12 -10
View File
@@ -29,18 +29,19 @@ type Exit struct {
} }
type GlobalOptions struct { type GlobalOptions struct {
Endpoint figtree.StringOption `json:"endpoint,omitempty" yaml:"endpoint,omitempty"` Endpoint figtree.StringOption `yaml:"endpoint,omitempty" json:"endpoint,omitempty"`
User figtree.StringOption `json:"user,omitempty" yaml:"user,omitempty"`
PasswordSource figtree.StringOption `json:"password-source,omitempty" yaml:"password-source,omitempty"`
UnixProxy figtree.StringOption `yaml:"unixproxy,omitempty" json:"unixproxy,omitempty"`
Insecure figtree.BoolOption `yaml:"insecure,omitempty" json:"insecure,omitempty"` Insecure figtree.BoolOption `yaml:"insecure,omitempty" json:"insecure,omitempty"`
PasswordSource figtree.StringOption `yaml:"password-source,omitempty" json:"password-source,omitempty"`
Quiet figtree.BoolOption `yaml:"quiet,omitempty" json:"quiet,omitempty"`
UnixProxy figtree.StringOption `yaml:"unixproxy,omitempty" json:"unixproxy,omitempty"`
User figtree.StringOption `yaml:"user,omitempty" json:"user,omitempty"`
} }
type CommonOptions struct { type CommonOptions struct {
Browse figtree.BoolOption `json:"browse,omitempty" yaml:"browse,omitempty"` Browse figtree.BoolOption `yaml:"browse,omitempty" json:"browse,omitempty"`
Editor figtree.StringOption `json:"editor,omitempty" yaml:"editor,omitempty"` Editor figtree.StringOption `yaml:"editor,omitempty" json:"editor,omitempty"`
SkipEditing figtree.BoolOption `json:"noedit,omitempty" yaml:"noedit,omitempty"` SkipEditing figtree.BoolOption `yaml:"noedit,omitempty" json:"noedit,omitempty"`
Template figtree.StringOption `json:"template,omitempty" yaml:"template,omitempty"` Template figtree.StringOption `yaml:"template,omitempty" json:"template,omitempty"`
} }
type CommandRegistryEntry struct { type CommandRegistryEntry struct {
@@ -67,9 +68,10 @@ func Register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree, re
User: figtree.NewStringOption(os.Getenv("USER")), User: figtree.NewStringOption(os.Getenv("USER")),
} }
app.Flag("endpoint", "Base URI to use for Jira").Short('e').SetValue(&globals.Endpoint) app.Flag("endpoint", "Base URI to use for Jira").Short('e').SetValue(&globals.Endpoint)
app.Flag("user", "Login name used for authentication with Jira service").Short('u').SetValue(&globals.User)
app.Flag("unixproxy", "Path for a unix-socket proxy").SetValue(&globals.UnixProxy)
app.Flag("insecure", "Disable TLS certificate verification").Short('k').SetValue(&globals.Insecure) app.Flag("insecure", "Disable TLS certificate verification").Short('k').SetValue(&globals.Insecure)
app.Flag("quiet", "Suppress output to console").Short('Q').SetValue(&globals.Quiet)
app.Flag("unixproxy", "Path for a unix-socket proxy").SetValue(&globals.UnixProxy)
app.Flag("user", "Login name used for authentication with Jira service").Short('u').SetValue(&globals.User)
app.PreAction(func(_ *kingpin.ParseContext) error { app.PreAction(func(_ *kingpin.ParseContext) error {
if globals.Insecure.Value { if globals.Insecure.Value {
+3 -1
View File
@@ -51,7 +51,9 @@ func CmdAssign(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AssignOptio
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
+4 -2
View File
@@ -65,8 +65,10 @@ func CmdBlock(o *oreo.Client, globals *jiracli.GlobalOptions, opts *BlockOptions
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key) fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
}
if opts.Browse.Value { if opts.Browse.Value {
if err := CmdBrowse(globals, opts.InwardIssue.Key); err != nil { if err := CmdBrowse(globals, opts.InwardIssue.Key); err != nil {
+3 -1
View File
@@ -67,7 +67,9 @@ func CmdComment(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CommentOpt
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
+3 -1
View File
@@ -61,6 +61,8 @@ func CmdComponentAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Compo
return err return err
} }
fmt.Printf("OK %s %s\n", component.Project, component.Name) if !globals.Quiet.Value {
fmt.Printf("OK %s %s\n", component.Project, component.Name)
}
return nil return nil
} }
+3 -1
View File
@@ -93,7 +93,9 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, globals.Endpoint.Value, issueResp.Key) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, globals.Endpoint.Value, issueResp.Key)
}
if opts.SaveFile != "" { if opts.SaveFile != "" {
fh, err := os.Create(opts.SaveFile) fh, err := os.Create(opts.SaveFile)
+6 -2
View File
@@ -66,7 +66,9 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
if err := jira.LinkIssues(o, globals.Endpoint.Value, &opts.LinkIssueRequest); err != nil { if err := jira.LinkIssues(o, globals.Endpoint.Value, &opts.LinkIssueRequest); err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
}
meta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key) meta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key)
if err != nil { if err != nil {
@@ -100,7 +102,9 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
} }
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key)
}
if opts.Browse.Value { if opts.Browse.Value {
if err := CmdBrowse(globals, opts.OutwardIssue.Key); err != nil { if err := CmdBrowse(globals, opts.OutwardIssue.Key); err != nil {
+6 -4
View File
@@ -84,8 +84,9 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
} }
@@ -111,8 +112,9 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, globals.Endpoint.Value, issueData.Key) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, globals.Endpoint.Value, issueData.Key)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, issueData.Key) return CmdBrowse(globals, issueData.Key)
} }
+5 -3
View File
@@ -29,7 +29,7 @@ func CmdExportTemplatesRegistry() *jiracli.CommandRegistryEntry {
return CmdExportTemplatesUsage(cmd, &opts) return CmdExportTemplatesUsage(cmd, &opts)
}, },
func(o *oreo.Client, globals *jiracli.GlobalOptions) error { func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
return CmdExportTemplates(&opts) return CmdExportTemplates(globals, &opts)
}, },
} }
} }
@@ -42,7 +42,7 @@ func CmdExportTemplatesUsage(cmd *kingpin.CmdClause, opts *ExportTemplatesOption
} }
// CmdExportTemplates will export templates to directory // CmdExportTemplates will export templates to directory
func CmdExportTemplates(opts *ExportTemplatesOptions) error { func CmdExportTemplates(globals *jiracli.GlobalOptions, opts *ExportTemplatesOptions) error {
if err := os.MkdirAll(opts.Dir, 0755); err != nil { if err := os.MkdirAll(opts.Dir, 0755); err != nil {
return err return err
} }
@@ -62,7 +62,9 @@ func CmdExportTemplates(opts *ExportTemplatesOptions) error {
return err return err
} }
defer fh.Close() defer fh.Close()
log.Noticef("Creating %s", templateFile) if !globals.Quiet.Value {
log.Noticef("Creating %s", templateFile)
}
fh.Write([]byte(template)) fh.Write([]byte(template))
} }
return nil return nil
+4 -2
View File
@@ -61,8 +61,10 @@ func CmdIssueLink(o *oreo.Client, globals *jiracli.GlobalOptions, opts *IssueLin
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key) fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
}
if opts.Browse.Value { if opts.Browse.Value {
if err := CmdBrowse(globals, opts.OutwardIssue.Key); err != nil { if err := CmdBrowse(globals, opts.OutwardIssue.Key); err != nil {
+3 -1
View File
@@ -56,7 +56,9 @@ func CmdLabelsAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsAd
if err := jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate); err != nil { if err := jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate); err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
} }
+3 -1
View File
@@ -57,7 +57,9 @@ func CmdLabelsRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Label
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
} }
+3 -1
View File
@@ -54,7 +54,9 @@ func CmdLabelsSet(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsSe
if err := jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate); err != nil { if err := jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate); err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
} }
+6 -2
View File
@@ -57,10 +57,14 @@ func CmdLogin(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.Comm
log.Errorf("%s", err) log.Errorf("%s", err)
continue continue
} }
fmt.Println(ansi.Color("OK", "green"), "New session for", globals.User) if !globals.Quiet.Value {
fmt.Println(ansi.Color("OK", "green"), "New session for", globals.User)
}
break break
} else { } else {
fmt.Println(ansi.Color("OK", "green"), "Found session for", session.Name) if !globals.Quiet.Value {
fmt.Println(ansi.Color("OK", "green"), "Found session for", session.Name)
}
break break
} }
} }
+3 -1
View File
@@ -30,7 +30,9 @@ func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.Com
ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks() ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks()
err := jira.DeleteSession(ua, globals.Endpoint.Value) err := jira.DeleteSession(ua, globals.Endpoint.Value)
if err == nil { if err == nil {
fmt.Println(ansi.Color("OK", "green"), "Terminated session for", globals.User) if !globals.Quiet.Value {
fmt.Println(ansi.Color("OK", "green"), "Terminated session for", globals.User)
}
} else { } else {
fmt.Printf("%s Failed to terminate session for %s: %s", ansi.Color("ERROR", "red"), globals.User, err) fmt.Printf("%s Failed to terminate session for %s: %s", ansi.Color("ERROR", "red"), globals.User, err)
} }
+4 -2
View File
@@ -58,8 +58,10 @@ func CmdRank(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RankOptions)
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.First, globals.Endpoint.Value, opts.First) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Second, globals.Endpoint.Value, opts.Second) fmt.Printf("OK %s %s/browse/%s\n", opts.First, globals.Endpoint.Value, opts.First)
fmt.Printf("OK %s %s/browse/%s\n", opts.Second, globals.Endpoint.Value, opts.Second)
}
if opts.Browse.Value { if opts.Browse.Value {
if err := CmdBrowse(globals, opts.First); err != nil { if err := CmdBrowse(globals, opts.First); err != nil {
+3 -1
View File
@@ -78,7 +78,9 @@ func CmdRequest(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RequestOpt
return err return err
} }
if len(content) == 0 { if len(content) == 0 {
fmt.Println("No Content") if !globals.Quiet.Value {
fmt.Println("No content in response")
}
return nil return nil
} }
var data interface{} var data interface{}
+3 -1
View File
@@ -107,7 +107,9 @@ func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOpt
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, globals.Endpoint.Value, issueResp.Key) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, globals.Endpoint.Value, issueResp.Key)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, issueResp.Key) return CmdBrowse(globals, issueResp.Key)
+3 -1
View File
@@ -146,7 +146,9 @@ func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Transit
if err != nil { if err != nil {
return jiracli.CliError(err) return jiracli.CliError(err)
} }
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, globals.Endpoint.Value, issueData.Key) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, globals.Endpoint.Value, issueData.Key)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
+8 -4
View File
@@ -27,13 +27,13 @@ func CmdUnexportTemplatesRegistry() *jiracli.CommandRegistryEntry {
return CmdExportTemplatesUsage(cmd, &opts) return CmdExportTemplatesUsage(cmd, &opts)
}, },
func(o *oreo.Client, globals *jiracli.GlobalOptions) error { func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
return CmdUnexportTemplates(&opts) return CmdUnexportTemplates(globals, &opts)
}, },
} }
} }
// CmdUnexportTemplates will remove unmodified templates from export directory // CmdUnexportTemplates will remove unmodified templates from export directory
func CmdUnexportTemplates(opts *ExportTemplatesOptions) error { func CmdUnexportTemplates(globals *jiracli.GlobalOptions, opts *ExportTemplatesOptions) error {
for name, template := range jiracli.AllTemplates { for name, template := range jiracli.AllTemplates {
if opts.Template != "" && opts.Template != name { if opts.Template != "" && opts.Template != name {
continue continue
@@ -49,10 +49,14 @@ func CmdUnexportTemplates(opts *ExportTemplatesOptions) error {
return err return err
} }
if bytes.Compare([]byte(template), contents) == 0 { if bytes.Compare([]byte(template), contents) == 0 {
log.Warning("Removing %s, template identical to default", templateFile) if !globals.Quiet.Value {
log.Notice("Removing %s, template identical to default", templateFile)
}
os.Remove(templateFile) os.Remove(templateFile)
} else { } else {
log.Warning("Skipping %s, found customizations to template", templateFile) if !globals.Quiet.Value {
log.Notice("Skipping %s, found customizations to template", templateFile)
}
} }
} }
return nil return nil
+3 -2
View File
@@ -63,8 +63,9 @@ func CmdVote(o *oreo.Client, globals *jiracli.GlobalOptions, opts *VoteOptions)
return err return err
} }
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
} }
+3 -1
View File
@@ -70,7 +70,9 @@ func CmdWatch(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WatchOptions
} }
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
+3 -1
View File
@@ -57,7 +57,9 @@ func CmdWorklogAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Worklog
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
}
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
} }