Skip to content

Commit

Permalink
add --quiet global option
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Sep 5, 2017
1 parent c0358eb commit c226077
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 46 deletions.
22 changes: 12 additions & 10 deletions jiracli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/assign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions jiracmd/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/componentAdd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion jiracmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions jiracmd/dup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions jiracmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
8 changes: 5 additions & 3 deletions jiracmd/exportTemplates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
Expand All @@ -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
}
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions jiracmd/issuelink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/labelsAdd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/labelsRemove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/labelsSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions jiracmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions jiracmd/rank.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/subtask.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions jiracmd/unexportTemplates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions jiracmd/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion jiracmd/worklogAdd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c226077

Please sign in to comment.