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
+3 -1
View File
@@ -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)
+4 -2
View File
@@ -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 {
+3 -1
View File
@@ -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)
+3 -1
View File
@@ -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
}
+3 -1
View File
@@ -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)
+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 {
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 {
+6 -4
View File
@@ -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)
}
+5 -3
View File
@@ -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
+4 -2
View File
@@ -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 {
+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 {
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)
}
+3 -1
View File
@@ -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)
}
+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 {
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)
}
+6 -2
View File
@@ -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
}
}
+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()
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)
}
+4 -2
View File
@@ -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 {
+3 -1
View File
@@ -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{}
+3 -1
View File
@@ -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)
+3 -1
View File
@@ -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)
+8 -4
View File
@@ -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
+3 -2
View File
@@ -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)
}
+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 {
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 {
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)
}