From c226077320dff651075be1f656716e51328a61d2 Mon Sep 17 00:00:00 2001 From: Cory Bennett Date: Mon, 4 Sep 2017 18:12:32 -0700 Subject: [PATCH] add --quiet global option --- jiracli/cli.go | 22 ++++++++++++---------- jiracmd/assign.go | 4 +++- jiracmd/block.go | 6 ++++-- jiracmd/comment.go | 4 +++- jiracmd/componentAdd.go | 4 +++- jiracmd/create.go | 4 +++- jiracmd/dup.go | 8 ++++++-- jiracmd/edit.go | 10 ++++++---- jiracmd/exportTemplates.go | 8 +++++--- jiracmd/issuelink.go | 6 ++++-- jiracmd/labelsAdd.go | 4 +++- jiracmd/labelsRemove.go | 4 +++- jiracmd/labelsSet.go | 4 +++- jiracmd/login.go | 8 ++++++-- jiracmd/logout.go | 4 +++- jiracmd/rank.go | 6 ++++-- jiracmd/request.go | 4 +++- jiracmd/subtask.go | 4 +++- jiracmd/transition.go | 4 +++- jiracmd/unexportTemplates.go | 12 ++++++++---- jiracmd/vote.go | 5 +++-- jiracmd/watch.go | 4 +++- jiracmd/worklogAdd.go | 4 +++- 23 files changed, 97 insertions(+), 46 deletions(-) diff --git a/jiracli/cli.go b/jiracli/cli.go index 7a8c8b9..5ec4fb9 100644 --- a/jiracli/cli.go +++ b/jiracli/cli.go @@ -29,18 +29,19 @@ type Exit struct { } type GlobalOptions struct { - Endpoint figtree.StringOption `json:"endpoint,omitempty" yaml:"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"` + Endpoint figtree.StringOption `yaml:"endpoint,omitempty" json:"endpoint,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 { - Browse figtree.BoolOption `json:"browse,omitempty" yaml:"browse,omitempty"` - Editor figtree.StringOption `json:"editor,omitempty" yaml:"editor,omitempty"` - SkipEditing figtree.BoolOption `json:"noedit,omitempty" yaml:"noedit,omitempty"` - Template figtree.StringOption `json:"template,omitempty" yaml:"template,omitempty"` + Browse figtree.BoolOption `yaml:"browse,omitempty" json:"browse,omitempty"` + Editor figtree.StringOption `yaml:"editor,omitempty" json:"editor,omitempty"` + SkipEditing figtree.BoolOption `yaml:"noedit,omitempty" json:"noedit,omitempty"` + Template figtree.StringOption `yaml:"template,omitempty" json:"template,omitempty"` } 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")), } 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("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 { if globals.Insecure.Value { diff --git a/jiracmd/assign.go b/jiracmd/assign.go index 9d106f9..d6514f9 100644 --- a/jiracmd/assign.go +++ b/jiracmd/assign.go @@ -51,7 +51,9 @@ func CmdAssign(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AssignOptio 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 { return CmdBrowse(globals, opts.Issue) diff --git a/jiracmd/block.go b/jiracmd/block.go index c7f8fab..63b066f 100644 --- a/jiracmd/block.go +++ b/jiracmd/block.go @@ -65,8 +65,10 @@ func CmdBlock(o *oreo.Client, globals *jiracli.GlobalOptions, opts *BlockOptions return err } - 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 !globals.Quiet.Value { + 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 err := CmdBrowse(globals, opts.InwardIssue.Key); err != nil { diff --git a/jiracmd/comment.go b/jiracmd/comment.go index 0e25620..2a7e5b1 100644 --- a/jiracmd/comment.go +++ b/jiracmd/comment.go @@ -67,7 +67,9 @@ func CmdComment(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CommentOpt 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 { return CmdBrowse(globals, opts.Issue) diff --git a/jiracmd/componentAdd.go b/jiracmd/componentAdd.go index 755aa05..d17eb6b 100644 --- a/jiracmd/componentAdd.go +++ b/jiracmd/componentAdd.go @@ -61,6 +61,8 @@ func CmdComponentAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Compo 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 } diff --git a/jiracmd/create.go b/jiracmd/create.go index b7bf600..11350ec 100644 --- a/jiracmd/create.go +++ b/jiracmd/create.go @@ -93,7 +93,9 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio 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 != "" { fh, err := os.Create(opts.SaveFile) diff --git a/jiracmd/dup.go b/jiracmd/dup.go index 6bf8144..0d004b2 100644 --- a/jiracmd/dup.go +++ b/jiracmd/dup.go @@ -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 { 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) 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 err := CmdBrowse(globals, opts.OutwardIssue.Key); err != nil { diff --git a/jiracmd/edit.go b/jiracmd/edit.go index 3f250fa..629186b 100644 --- a/jiracmd/edit.go +++ b/jiracmd/edit.go @@ -84,8 +84,9 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions) if err != nil { 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 { return CmdBrowse(globals, opts.Issue) } @@ -111,8 +112,9 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions) if err != nil { 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 { return CmdBrowse(globals, issueData.Key) } diff --git a/jiracmd/exportTemplates.go b/jiracmd/exportTemplates.go index 6fd2e16..bb6dbe6 100644 --- a/jiracmd/exportTemplates.go +++ b/jiracmd/exportTemplates.go @@ -29,7 +29,7 @@ func CmdExportTemplatesRegistry() *jiracli.CommandRegistryEntry { return CmdExportTemplatesUsage(cmd, &opts) }, 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 -func CmdExportTemplates(opts *ExportTemplatesOptions) error { +func CmdExportTemplates(globals *jiracli.GlobalOptions, opts *ExportTemplatesOptions) error { if err := os.MkdirAll(opts.Dir, 0755); err != nil { return err } @@ -62,7 +62,9 @@ func CmdExportTemplates(opts *ExportTemplatesOptions) error { return err } defer fh.Close() - log.Noticef("Creating %s", templateFile) + if !globals.Quiet.Value { + log.Noticef("Creating %s", templateFile) + } fh.Write([]byte(template)) } return nil diff --git a/jiracmd/issuelink.go b/jiracmd/issuelink.go index cfdb751..adf1649 100644 --- a/jiracmd/issuelink.go +++ b/jiracmd/issuelink.go @@ -61,8 +61,10 @@ func CmdIssueLink(o *oreo.Client, globals *jiracli.GlobalOptions, opts *IssueLin return err } - 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 !globals.Quiet.Value { + 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 err := CmdBrowse(globals, opts.OutwardIssue.Key); err != nil { diff --git a/jiracmd/labelsAdd.go b/jiracmd/labelsAdd.go index 8755edb..98a8463 100644 --- a/jiracmd/labelsAdd.go +++ b/jiracmd/labelsAdd.go @@ -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 { 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 { return CmdBrowse(globals, opts.Issue) } diff --git a/jiracmd/labelsRemove.go b/jiracmd/labelsRemove.go index 7467b2f..1271f6c 100644 --- a/jiracmd/labelsRemove.go +++ b/jiracmd/labelsRemove.go @@ -57,7 +57,9 @@ func CmdLabelsRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Label if err != nil { 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 { return CmdBrowse(globals, opts.Issue) } diff --git a/jiracmd/labelsSet.go b/jiracmd/labelsSet.go index ba606b9..2584024 100644 --- a/jiracmd/labelsSet.go +++ b/jiracmd/labelsSet.go @@ -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 { 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 { return CmdBrowse(globals, opts.Issue) } diff --git a/jiracmd/login.go b/jiracmd/login.go index bbb2178..e7e950c 100644 --- a/jiracmd/login.go +++ b/jiracmd/login.go @@ -57,10 +57,14 @@ func CmdLogin(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.Comm log.Errorf("%s", err) 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 } 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 } } diff --git a/jiracmd/logout.go b/jiracmd/logout.go index d096d3e..86275de 100644 --- a/jiracmd/logout.go +++ b/jiracmd/logout.go @@ -30,7 +30,9 @@ func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.Com ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks() err := jira.DeleteSession(ua, globals.Endpoint.Value) 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 { fmt.Printf("%s Failed to terminate session for %s: %s", ansi.Color("ERROR", "red"), globals.User, err) } diff --git a/jiracmd/rank.go b/jiracmd/rank.go index f4fa5c5..831a807 100644 --- a/jiracmd/rank.go +++ b/jiracmd/rank.go @@ -58,8 +58,10 @@ func CmdRank(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RankOptions) return err } - 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 !globals.Quiet.Value { + 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 err := CmdBrowse(globals, opts.First); err != nil { diff --git a/jiracmd/request.go b/jiracmd/request.go index 05d8c53..af68e71 100644 --- a/jiracmd/request.go +++ b/jiracmd/request.go @@ -78,7 +78,9 @@ func CmdRequest(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RequestOpt return err } if len(content) == 0 { - fmt.Println("No Content") + if !globals.Quiet.Value { + fmt.Println("No content in response") + } return nil } var data interface{} diff --git a/jiracmd/subtask.go b/jiracmd/subtask.go index 24a10ee..8f50cdf 100644 --- a/jiracmd/subtask.go +++ b/jiracmd/subtask.go @@ -107,7 +107,9 @@ func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOpt 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 { return CmdBrowse(globals, issueResp.Key) diff --git a/jiracmd/transition.go b/jiracmd/transition.go index 3c2689f..5cd4cad 100644 --- a/jiracmd/transition.go +++ b/jiracmd/transition.go @@ -146,7 +146,9 @@ func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Transit if err != nil { 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 { return CmdBrowse(globals, opts.Issue) diff --git a/jiracmd/unexportTemplates.go b/jiracmd/unexportTemplates.go index c0023af..9ed69b4 100644 --- a/jiracmd/unexportTemplates.go +++ b/jiracmd/unexportTemplates.go @@ -27,13 +27,13 @@ func CmdUnexportTemplatesRegistry() *jiracli.CommandRegistryEntry { return CmdExportTemplatesUsage(cmd, &opts) }, func(o *oreo.Client, globals *jiracli.GlobalOptions) error { - return CmdUnexportTemplates(&opts) + return CmdUnexportTemplates(globals, &opts) }, } } // 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 { if opts.Template != "" && opts.Template != name { continue @@ -49,10 +49,14 @@ func CmdUnexportTemplates(opts *ExportTemplatesOptions) error { return err } 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) } 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 diff --git a/jiracmd/vote.go b/jiracmd/vote.go index e1b1986..36464fe 100644 --- a/jiracmd/vote.go +++ b/jiracmd/vote.go @@ -63,8 +63,9 @@ func CmdVote(o *oreo.Client, globals *jiracli.GlobalOptions, opts *VoteOptions) 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 { return CmdBrowse(globals, opts.Issue) } diff --git a/jiracmd/watch.go b/jiracmd/watch.go index c5acd88..b2b3942 100644 --- a/jiracmd/watch.go +++ b/jiracmd/watch.go @@ -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 { return CmdBrowse(globals, opts.Issue) diff --git a/jiracmd/worklogAdd.go b/jiracmd/worklogAdd.go index 835bce4..d6186d2 100644 --- a/jiracmd/worklogAdd.go +++ b/jiracmd/worklogAdd.go @@ -57,7 +57,9 @@ func CmdWorklogAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Worklog if err != nil { 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 { return CmdBrowse(globals, opts.Issue) }