refactor for GlobalOptions and CommonOptions

This commit is contained in:
Cory Bennett
2017-09-02 14:05:27 -07:00
parent 65891e7b3b
commit 979da1f3a5
37 changed files with 544 additions and 647 deletions
+48 -47
View File
@@ -15,6 +15,7 @@ import (
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracmd"
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
"gopkg.in/op/go-logging.v1" "gopkg.in/op/go-logging.v1"
) )
@@ -100,200 +101,200 @@ func main() {
registry := []jiracli.CommandRegistry{ registry := []jiracli.CommandRegistry{
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "login", Command: "login",
Entry: jiracli.CmdLoginRegistry(fig, o), Entry: jiracmd.CmdLoginRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "logout", Command: "logout",
Entry: jiracli.CmdLogoutRegistry(fig, o), Entry: jiracmd.CmdLogoutRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "list", Command: "list",
Aliases: []string{"ls"}, Aliases: []string{"ls"},
Entry: jiracli.CmdListRegistry(fig, o), Entry: jiracmd.CmdListRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "view", Command: "view",
Entry: jiracli.CmdViewRegistry(fig, o), Entry: jiracmd.CmdViewRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "create", Command: "create",
Entry: jiracli.CmdCreateRegistry(fig, o), Entry: jiracmd.CmdCreateRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "edit", Command: "edit",
Entry: jiracli.CmdEditRegistry(fig, o), Entry: jiracmd.CmdEditRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "comment", Command: "comment",
Entry: jiracli.CmdCommentRegistry(fig, o), Entry: jiracmd.CmdCommentRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "worklog list", Command: "worklog list",
Entry: jiracli.CmdWorklogListRegistry(fig, o), Entry: jiracmd.CmdWorklogListRegistry(o),
Default: true, Default: true,
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "worklog add", Command: "worklog add",
Entry: jiracli.CmdWorklogAddRegistry(fig, o), Entry: jiracmd.CmdWorklogAddRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "fields", Command: "fields",
Entry: jiracli.CmdFieldsRegistry(fig, o), Entry: jiracmd.CmdFieldsRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "createmeta", Command: "createmeta",
Entry: jiracli.CmdCreateMetaRegistry(fig, o), Entry: jiracmd.CmdCreateMetaRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "editmeta", Command: "editmeta",
Entry: jiracli.CmdEditMetaRegistry(fig, o), Entry: jiracmd.CmdEditMetaRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "subtask", Command: "subtask",
Entry: jiracli.CmdSubtaskRegistry(fig, o), Entry: jiracmd.CmdSubtaskRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "dup", Command: "dup",
Entry: jiracli.CmdDupRegistry(fig, o), Entry: jiracmd.CmdDupRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "block", Command: "block",
Entry: jiracli.CmdBlockRegistry(fig, o), Entry: jiracmd.CmdBlockRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "issuelink", Command: "issuelink",
Entry: jiracli.CmdIssueLinkRegistry(fig, o), Entry: jiracmd.CmdIssueLinkRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "issuelinktypes", Command: "issuelinktypes",
Entry: jiracli.CmdIssueLinkTypesRegistry(fig, o), Entry: jiracmd.CmdIssueLinkTypesRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "transition", Command: "transition",
Aliases: []string{"trans"}, Aliases: []string{"trans"},
Entry: jiracli.CmdTransitionRegistry(fig, o, ""), Entry: jiracmd.CmdTransitionRegistry(o, ""),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "transitions", Command: "transitions",
Entry: jiracli.CmdTransitionsRegistry(fig, o, "transitions"), Entry: jiracmd.CmdTransitionsRegistry(o, "transitions"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "transmeta", Command: "transmeta",
Entry: jiracli.CmdTransitionsRegistry(fig, o, "debug"), Entry: jiracmd.CmdTransitionsRegistry(o, "debug"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "close", Command: "close",
Entry: jiracli.CmdTransitionRegistry(fig, o, "close"), Entry: jiracmd.CmdTransitionRegistry(o, "close"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "acknowledge", Command: "acknowledge",
Aliases: []string{"ack"}, Aliases: []string{"ack"},
Entry: jiracli.CmdTransitionRegistry(fig, o, "acknowledge"), Entry: jiracmd.CmdTransitionRegistry(o, "acknowledge"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "reopen", Command: "reopen",
Entry: jiracli.CmdTransitionRegistry(fig, o, "reopen"), Entry: jiracmd.CmdTransitionRegistry(o, "reopen"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "resolve", Command: "resolve",
Entry: jiracli.CmdTransitionRegistry(fig, o, "resolve"), Entry: jiracmd.CmdTransitionRegistry(o, "resolve"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "start", Command: "start",
Entry: jiracli.CmdTransitionRegistry(fig, o, "start"), Entry: jiracmd.CmdTransitionRegistry(o, "start"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "stop", Command: "stop",
Entry: jiracli.CmdTransitionRegistry(fig, o, "stop"), Entry: jiracmd.CmdTransitionRegistry(o, "stop"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "todo", Command: "todo",
Entry: jiracli.CmdTransitionRegistry(fig, o, "To Do"), Entry: jiracmd.CmdTransitionRegistry(o, "To Do"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "backlog", Command: "backlog",
Entry: jiracli.CmdTransitionRegistry(fig, o, "Backlog"), Entry: jiracmd.CmdTransitionRegistry(o, "Backlog"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "done", Command: "done",
Entry: jiracli.CmdTransitionRegistry(fig, o, "Done"), Entry: jiracmd.CmdTransitionRegistry(o, "Done"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "in-progress", Command: "in-progress",
Aliases: []string{"prog", "progress"}, Aliases: []string{"prog", "progress"},
Entry: jiracli.CmdTransitionRegistry(fig, o, "Progress"), Entry: jiracmd.CmdTransitionRegistry(o, "Progress"),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "vote", Command: "vote",
Entry: jiracli.CmdVoteRegistry(fig, o), Entry: jiracmd.CmdVoteRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "rank", Command: "rank",
Entry: jiracli.CmdRankRegistry(fig, o), Entry: jiracmd.CmdRankRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "watch", Command: "watch",
Entry: jiracli.CmdWatchRegistry(fig, o), Entry: jiracmd.CmdWatchRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "labels add", Command: "labels add",
Entry: jiracli.CmdLabelsAddRegistry(fig, o), Entry: jiracmd.CmdLabelsAddRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "labels set", Command: "labels set",
Entry: jiracli.CmdLabelsAddRegistry(fig, o), Entry: jiracmd.CmdLabelsAddRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "labels remove", Command: "labels remove",
Entry: jiracli.CmdLabelsAddRegistry(fig, o), Entry: jiracmd.CmdLabelsAddRegistry(o),
Aliases: []string{"rm"}, Aliases: []string{"rm"},
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "take", Command: "take",
Entry: jiracli.CmdTakeRegistry(fig, o), Entry: jiracmd.CmdTakeRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "assign", Command: "assign",
Entry: jiracli.CmdAssignRegistry(fig, o), Entry: jiracmd.CmdAssignRegistry(o),
Aliases: []string{"give"}, Aliases: []string{"give"},
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "unassign", Command: "unassign",
Entry: jiracli.CmdUnassignRegistry(fig, o), Entry: jiracmd.CmdUnassignRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "component add", Command: "component add",
Entry: jiracli.CmdComponentAddRegistry(fig, o), Entry: jiracmd.CmdComponentAddRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "components", Command: "components",
Entry: jiracli.CmdComponentsRegistry(fig, o), Entry: jiracmd.CmdComponentsRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "issuetypes", Command: "issuetypes",
Entry: jiracli.CmdIssueTypesRegistry(fig, o), Entry: jiracmd.CmdIssueTypesRegistry(o),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "export-templates", Command: "export-templates",
Entry: jiracli.CmdExportTemplatesRegistry(fig), Entry: jiracmd.CmdExportTemplatesRegistry(),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "unexport-templates", Command: "unexport-templates",
Entry: jiracli.CmdUnexportTemplatesRegistry(fig), Entry: jiracmd.CmdUnexportTemplatesRegistry(),
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "browse", Command: "browse",
Entry: jiracli.CmdBrowseRegistry(fig), Entry: jiracmd.CmdBrowseRegistry(),
Aliases: []string{"b"}, Aliases: []string{"b"},
}, },
jiracli.CommandRegistry{ jiracli.CommandRegistry{
Command: "request", Command: "request",
Entry: jiracli.CmdRequestRegistry(fig, o), Entry: jiracmd.CmdRequestRegistry(o),
Aliases: []string{"req"}, Aliases: []string{"req"},
}, },
} }
jiracli.Register(app, registry) jiracli.Register(app, fig, registry)
// register custom commands // register custom commands
data := struct { data := struct {
+26 -27
View File
@@ -26,19 +26,22 @@ type Exit struct {
} }
type GlobalOptions struct { type GlobalOptions struct {
Browse figtree.BoolOption `json:"browse,omitempty" yaml:"browse,omitempty"`
Editor figtree.StringOption `json:"editor,omitempty" yaml:"editor,omitempty"`
Endpoint figtree.StringOption `json:"endpoint,omitempty" yaml:"endpoint,omitempty"` Endpoint figtree.StringOption `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
SkipEditing figtree.BoolOption `json:"noedit,omitempty" yaml:"noedit,omitempty"`
PasswordSource figtree.StringOption `json:"password-source,omitempty" yaml:"password-source,omitempty"`
Template figtree.StringOption `json:"template,omitempty" yaml:"template,omitempty"`
User figtree.StringOption `json:"user,omitempty" yaml:"user,omitempty"` User figtree.StringOption `json:"user,omitempty" yaml:"user,omitempty"`
PasswordSource figtree.StringOption `json:"password-source,omitempty" yaml:"password-source,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"`
} }
type CommandRegistryEntry struct { type CommandRegistryEntry struct {
Help string Help string
ExecuteFunc func() error UsageFunc func(*figtree.FigTree, *kingpin.CmdClause) error
UsageFunc func(*kingpin.CmdClause) error ExecuteFunc func(*GlobalOptions) error
} }
type CommandRegistry struct { type CommandRegistry struct {
@@ -54,7 +57,13 @@ type kingpinAppOrCommand interface {
GetCommand(string) *kingpin.CmdClause GetCommand(string) *kingpin.CmdClause
} }
func Register(app *kingpin.Application, reg []CommandRegistry) { func Register(app *kingpin.Application, fig *figtree.FigTree, reg []CommandRegistry) {
globals := GlobalOptions{
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)
for _, command := range reg { for _, command := range reg {
copy := command copy := command
commandFields := strings.Fields(copy.Command) commandFields := strings.Fields(copy.Command)
@@ -70,6 +79,8 @@ func Register(app *kingpin.Application, reg []CommandRegistry) {
} }
cmd := appOrCmd.Command(commandFields[len(commandFields)-1], copy.Entry.Help) cmd := appOrCmd.Command(commandFields[len(commandFields)-1], copy.Entry.Help)
LoadConfigs(cmd, fig, &globals)
for _, alias := range copy.Aliases { for _, alias := range copy.Aliases {
cmd = cmd.Alias(alias) cmd = cmd.Alias(alias)
} }
@@ -77,29 +88,17 @@ func Register(app *kingpin.Application, reg []CommandRegistry) {
cmd = cmd.Default() cmd = cmd.Default()
} }
if copy.Entry.UsageFunc != nil { if copy.Entry.UsageFunc != nil {
copy.Entry.UsageFunc(cmd) copy.Entry.UsageFunc(fig, cmd)
} }
cmd.Action( cmd.Action(
func(_ *kingpin.ParseContext) error { func(_ *kingpin.ParseContext) error {
return copy.Entry.ExecuteFunc() return copy.Entry.ExecuteFunc(&globals)
}, },
) )
} }
} }
func GlobalUsage(cmd *kingpin.CmdClause, opts *GlobalOptions) error {
cmd.PreAction(func(_ *kingpin.ParseContext) error {
if opts.User.Value == "" {
opts.User = figtree.NewStringOption(os.Getenv("USER"))
}
return nil
})
cmd.Flag("endpoint", "Base URI to use for Jira").Short('e').SetValue(&opts.Endpoint)
cmd.Flag("user", "Login name used for authentication with Jira service").Short('u').SetValue(&opts.User)
return nil
}
func LoadConfigs(cmd *kingpin.CmdClause, fig *figtree.FigTree, opts interface{}) { func LoadConfigs(cmd *kingpin.CmdClause, fig *figtree.FigTree, opts interface{}) {
cmd.PreAction(func(_ *kingpin.ParseContext) error { cmd.PreAction(func(_ *kingpin.ParseContext) error {
os.Setenv("JIRA_OPERATION", cmd.FullCommand()) os.Setenv("JIRA_OPERATION", cmd.FullCommand())
@@ -112,19 +111,19 @@ func LoadConfigs(cmd *kingpin.CmdClause, fig *figtree.FigTree, opts interface{})
}) })
} }
func BrowseUsage(cmd *kingpin.CmdClause, opts *GlobalOptions) { func BrowseUsage(cmd *kingpin.CmdClause, opts *CommonOptions) {
cmd.Flag("browse", "Open issue(s) in browser after operation").Short('b').SetValue(&opts.Browse) cmd.Flag("browse", "Open issue(s) in browser after operation").Short('b').SetValue(&opts.Browse)
} }
func EditorUsage(cmd *kingpin.CmdClause, opts *GlobalOptions) { func EditorUsage(cmd *kingpin.CmdClause, opts *CommonOptions) {
cmd.Flag("editor", "Editor to use").SetValue(&opts.Editor) cmd.Flag("editor", "Editor to use").SetValue(&opts.Editor)
} }
func TemplateUsage(cmd *kingpin.CmdClause, opts *GlobalOptions) { func TemplateUsage(cmd *kingpin.CmdClause, opts *CommonOptions) {
cmd.Flag("template", "Template to use for output").Short('t').SetValue(&opts.Template) cmd.Flag("template", "Template to use for output").Short('t').SetValue(&opts.Template)
} }
func (o *GlobalOptions) editFile(fileName string) (changes bool, err error) { func (o *CommonOptions) editFile(fileName string) (changes bool, err error) {
var editor string var editor string
for _, ed := range []string{o.Editor.Value, os.Getenv("JIRA_EDITOR"), os.Getenv("EDITOR"), "vim"} { for _, ed := range []string{o.Editor.Value, os.Getenv("JIRA_EDITOR"), os.Getenv("EDITOR"), "vim"} {
if ed != "" { if ed != "" {
@@ -187,7 +186,7 @@ func (o *GlobalOptions) editFile(fileName string) (changes bool, err error) {
return false, err return false, err
} }
func EditLoop(opts *GlobalOptions, input interface{}, output interface{}, submit func() error) error { func EditLoop(opts *CommonOptions, input interface{}, output interface{}, submit func() error) error {
tmpFile, err := tmpTemplate(opts.Template.Value, input) tmpFile, err := tmpTemplate(opts.Template.Value, input)
if err != nil { if err != nil {
return err return err
+13 -17
View File
@@ -5,38 +5,34 @@ import (
"github.com/coryb/figtree" "github.com/coryb/figtree"
"github.com/coryb/oreo" "github.com/coryb/oreo"
"gopkg.in/Netflix-Skunkworks/go-jira.v1" "gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
type AssignOptions struct { type AssignOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Assignee string `yaml:"assignee,omitempty" json:"assignee,omitempty"` Assignee string `yaml:"assignee,omitempty" json:"assignee,omitempty"`
} }
func CmdAssignRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdAssignRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := AssignOptions{} opts := AssignOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Assign user to issue", "Assign user to issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdAssign(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdAssignUsage(cmd, &opts) return CmdAssignUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdAssign(o, globals, &opts)
},
} }
} }
func CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error { func CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
cmd.Flag("default", "use default user for assignee").PreAction(func(ctx *kingpin.ParseContext) error { cmd.Flag("default", "use default user for assignee").PreAction(func(ctx *kingpin.ParseContext) error {
if jiracli.FlagValue(ctx, "default") == "true" { if jiracli.FlagValue(ctx, "default") == "true" {
opts.Assignee = "-1" opts.Assignee = "-1"
@@ -49,16 +45,16 @@ func CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
} }
// CmdAssign will assign an issue to a user // CmdAssign will assign an issue to a user
func CmdAssign(o *oreo.Client, opts *AssignOptions) error { func CmdAssign(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AssignOptions) error {
err := jira.IssueAssign(o, opts.Endpoint.Value, opts.Issue, opts.Assignee) err := jira.IssueAssign(o, globals.Endpoint.Value, opts.Issue, opts.Assignee)
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue) 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(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
+16 -19
View File
@@ -13,13 +13,13 @@ import (
) )
type BlockOptions struct { type BlockOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"` jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"`
} }
func CmdBlockRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdBlockRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := BlockOptions{ opts := BlockOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("edit"), Template: figtree.NewStringOption("edit"),
}, },
LinkIssueRequest: jiradata.LinkIssueRequest{ LinkIssueRequest: jiradata.LinkIssueRequest{
@@ -33,23 +33,20 @@ func CmdBlockRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegi
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Mark issues as blocker", "Mark issues as blocker",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdBlock(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdBlockUsage(cmd, &opts) return CmdBlockUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdBlock(o, globals, &opts)
},
} }
} }
func CmdBlockUsage(cmd *kingpin.CmdClause, opts *BlockOptions) error { func CmdBlockUsage(cmd *kingpin.CmdClause, opts *BlockOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.EditorUsage(cmd, &opts.CommonOptions)
} jiracli.TemplateUsage(cmd, &opts.CommonOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("comment", "Comment message when marking issue as blocker").Short('m').PreAction(func(ctx *kingpin.ParseContext) error { cmd.Flag("comment", "Comment message when marking issue as blocker").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Comment = &jiradata.Comment{ opts.Comment = &jiradata.Comment{
Body: jiracli.FlagValue(ctx, "comment"), Body: jiracli.FlagValue(ctx, "comment"),
@@ -63,17 +60,17 @@ func CmdBlockUsage(cmd *kingpin.CmdClause, opts *BlockOptions) error {
// CmdBlock will update the given issue as being a duplicate by the given dup issue // CmdBlock will update the given issue as being a duplicate by the given dup issue
// and will attempt to resolve the dup issue // and will attempt to resolve the dup issue
func CmdBlock(o *oreo.Client, opts *BlockOptions) error { func CmdBlock(o *oreo.Client, globals *jiracli.GlobalOptions, opts *BlockOptions) error {
if err := jira.LinkIssues(o, opts.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.InwardIssue.Key, opts.Endpoint.Value, opts.InwardIssue.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, opts.Endpoint.Value, opts.OutwardIssue.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(&BrowseOptions{opts.GlobalOptions, opts.InwardIssue.Key}); err != nil { if err := CmdBrowse(globals, opts.InwardIssue.Key); err != nil {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.OutwardIssue.Key}) return CmdBrowse(globals, opts.OutwardIssue.Key)
} }
} }
+9 -23
View File
@@ -9,36 +9,22 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
type BrowseOptions struct { func CmdBrowseRegistry() *jiracli.CommandRegistryEntry {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` issue := ""
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdBrowseRegistry(fig *figtree.FigTree) *jiracli.CommandRegistryEntry {
opts := BrowseOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Open issue in browser", "Open issue in browser",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdBrowse(&opts) cmd.Arg("ISSUE", "Issue to browse to").Required().StringVar(&issue)
return nil
}, },
func(cmd *kingpin.CmdClause) error { func(globals *jiracli.GlobalOptions) error {
jiracli.LoadConfigs(cmd, fig, &opts) return CmdBrowse(globals, issue)
return CmdBrowseUsage(cmd, &opts)
}, },
} }
} }
func CmdBrowseUsage(cmd *kingpin.CmdClause, opts *BrowseOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
cmd.Arg("ISSUE", "Issue to browse to").Required().StringVar(&opts.Issue)
return nil
}
// CmdBrowse open the default system browser to the provided issue // CmdBrowse open the default system browser to the provided issue
func CmdBrowse(opts *BrowseOptions) error { func CmdBrowse(globals *jiracli.GlobalOptions, issue string) error {
return browser.OpenURL(fmt.Sprintf("%s/browse/%s", opts.Endpoint.Value, opts.Issue)) return browser.OpenURL(fmt.Sprintf("%s/browse/%s", globals.Endpoint.Value, issue))
} }
+17 -20
View File
@@ -13,14 +13,14 @@ import (
) )
type CommentOptions struct { type CommentOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"` Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
} }
func CmdCommentRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdCommentRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := CommentOptions{ opts := CommentOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("comment"), Template: figtree.NewStringOption("comment"),
}, },
Overrides: map[string]string{}, Overrides: map[string]string{},
@@ -28,23 +28,20 @@ func CmdCommentRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRe
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Add comment to issue", "Add comment to issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdComment(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdCommentUsage(cmd, &opts) return CmdCommentUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdComment(o, globals, &opts)
},
} }
} }
func CmdCommentUsage(cmd *kingpin.CmdClause, opts *CommentOptions) error { func CmdCommentUsage(cmd *kingpin.CmdClause, opts *CommentOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.EditorUsage(cmd, &opts.CommonOptions)
} jiracli.TemplateUsage(cmd, &opts.CommonOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error { cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment") opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment")
return nil return nil
@@ -54,25 +51,25 @@ func CmdCommentUsage(cmd *kingpin.CmdClause, opts *CommentOptions) error {
} }
// CmdComment will update issue with comment // CmdComment will update issue with comment
func CmdComment(o *oreo.Client, opts *CommentOptions) error { func CmdComment(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CommentOptions) error {
comment := jiradata.Comment{} comment := jiradata.Comment{}
input := struct { input := struct {
Overrides map[string]string Overrides map[string]string
}{ }{
opts.Overrides, opts.Overrides,
} }
err := jiracli.EditLoop(&opts.GlobalOptions, &input, &comment, func() error { err := jiracli.EditLoop(&opts.CommonOptions, &input, &comment, func() error {
_, err := jira.IssueAddComment(o, opts.Endpoint.Value, opts.Issue, &comment) _, err := jira.IssueAddComment(o, globals.Endpoint.Value, opts.Issue, &comment)
return err return err
}) })
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue) 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(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
+13 -16
View File
@@ -13,35 +13,32 @@ import (
) )
type ComponentAddOptions struct { type ComponentAddOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.Component `yaml:",inline" json:",inline" figtree:",inline"` jiradata.Component `yaml:",inline" json:",inline" figtree:",inline"`
} }
func CmdComponentAddRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdComponentAddRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := ComponentAddOptions{ opts := ComponentAddOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("component-add"), Template: figtree.NewStringOption("component-add"),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Add component", "Add component",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdComponentAdd(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdComponentAddUsage(cmd, &opts) return CmdComponentAddUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdComponentAdd(o, globals, &opts)
},
} }
} }
func CmdComponentAddUsage(cmd *kingpin.CmdClause, opts *ComponentAddOptions) error { func CmdComponentAddUsage(cmd *kingpin.CmdClause, opts *ComponentAddOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.EditorUsage(cmd, &opts.CommonOptions)
return err jiracli.TemplateUsage(cmd, &opts.CommonOptions)
}
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing) cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("project", "project to create component in").Short('p').StringVar(&opts.Project) cmd.Flag("project", "project to create component in").Short('p').StringVar(&opts.Project)
cmd.Flag("name", "name of component").Short('n').StringVar(&opts.Name) cmd.Flag("name", "name of component").Short('n').StringVar(&opts.Name)
@@ -52,12 +49,12 @@ func CmdComponentAddUsage(cmd *kingpin.CmdClause, opts *ComponentAddOptions) err
// CmdComponentAdd sends the provided overrides to the "component-add" template for editing, then // CmdComponentAdd sends the provided overrides to the "component-add" template for editing, then
// will parse the edited document as YAML and submit the document to jira. // will parse the edited document as YAML and submit the document to jira.
func CmdComponentAdd(o *oreo.Client, opts *ComponentAddOptions) error { func CmdComponentAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ComponentAddOptions) error {
var err error var err error
component := &jiradata.Component{} component := &jiradata.Component{}
var resp *jiradata.Component var resp *jiradata.Component
err = jiracli.EditLoop(&opts.GlobalOptions, &opts.Component, component, func() error { err = jiracli.EditLoop(&opts.CommonOptions, &opts.Component, component, func() error {
resp, err = jira.CreateComponent(o, opts.Endpoint.Value, component) resp, err = jira.CreateComponent(o, globals.Endpoint.Value, component)
return err return err
}) })
if err != nil { if err != nil {
+11 -14
View File
@@ -12,45 +12,42 @@ import (
) )
type ComponentsOptions struct { type ComponentsOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"` Project string `yaml:"project,omitempty" json:"project,omitempty"`
} }
func CmdComponentsRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdComponentsRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := ComponentsOptions{ opts := ComponentsOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("components"), Template: figtree.NewStringOption("components"),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Show components for a project", "Show components for a project",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdComponents(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdComponentsUsage(cmd, &opts) return CmdComponentsUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdComponents(o, globals, &opts)
},
} }
} }
func CmdComponentsUsage(cmd *kingpin.CmdClause, opts *ComponentsOptions) error { func CmdComponentsUsage(cmd *kingpin.CmdClause, opts *ComponentsOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.TemplateUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("project", "project to list components").Short('p').StringVar(&opts.Project) cmd.Flag("project", "project to list components").Short('p').StringVar(&opts.Project)
return nil return nil
} }
// CmdComponents will get available components for project and send to the "components" template // CmdComponents will get available components for project and send to the "components" template
func CmdComponents(o *oreo.Client, opts *ComponentsOptions) error { func CmdComponents(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ComponentsOptions) error {
if opts.Project == "" { if opts.Project == "" {
return fmt.Errorf("Project Required.") return fmt.Errorf("Project Required.")
} }
data, err := jira.GetProjectComponents(o, opts.Endpoint.Value, opts.Project) data, err := jira.GetProjectComponents(o, globals.Endpoint.Value, opts.Project)
if err != nil { if err != nil {
return err return err
} }
+24 -27
View File
@@ -15,17 +15,17 @@ import (
) )
type CreateOptions struct { type CreateOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"` jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"` Project string `yaml:"project,omitempty" json:"project,omitempty"`
IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"` IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"` Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
SaveFile string `yaml:"savefile,omitempty" json:"savefile,omitempty"` SaveFile string `yaml:"savefile,omitempty" json:"savefile,omitempty"`
} }
func CmdCreateRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdCreateRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := CreateOptions{ opts := CreateOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("create"), Template: figtree.NewStringOption("create"),
}, },
Overrides: map[string]string{}, Overrides: map[string]string{},
@@ -33,23 +33,20 @@ func CmdCreateRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandReg
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Create issue", "Create issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdCreate(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdCreateUsage(cmd, &opts) return CmdCreateUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdCreate(o, globals, &opts)
},
} }
} }
func CmdCreateUsage(cmd *kingpin.CmdClause, opts *CreateOptions) error { func CmdCreateUsage(cmd *kingpin.CmdClause, opts *CreateOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.EditorUsage(cmd, &opts.CommonOptions)
} jiracli.TemplateUsage(cmd, &opts.CommonOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing) cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("project", "project to create issue in").Short('p').StringVar(&opts.Project) cmd.Flag("project", "project to create issue in").Short('p').StringVar(&opts.Project)
cmd.Flag("issuetype", "issuetype in to create").Short('i').StringVar(&opts.IssueType) cmd.Flag("issuetype", "issuetype in to create").Short('i').StringVar(&opts.IssueType)
@@ -64,16 +61,16 @@ func CmdCreateUsage(cmd *kingpin.CmdClause, opts *CreateOptions) error {
// CmdCreate sends the create-metadata to the "create" template for editing, then // CmdCreate sends the create-metadata to the "create" template for editing, then
// will parse the edited document as YAML and submit the document to jira. // will parse the edited document as YAML and submit the document to jira.
func CmdCreate(o *oreo.Client, opts *CreateOptions) error { func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptions) error {
type templateInput struct { type templateInput struct {
Meta *jiradata.IssueType `yaml:"meta" json:"meta"` Meta *jiradata.IssueType `yaml:"meta" json:"meta"`
Overrides map[string]string `yaml:"overrides" json:"overrides"` Overrides map[string]string `yaml:"overrides" json:"overrides"`
} }
if err := defaultIssueType(o, opts.Endpoint.Value, &opts.Project, &opts.IssueType); err != nil { if err := defaultIssueType(o, globals.Endpoint.Value, &opts.Project, &opts.IssueType); err != nil {
return err return err
} }
createMeta, err := jira.GetIssueCreateMetaIssueType(o, opts.Endpoint.Value, opts.Project, opts.IssueType) createMeta, err := jira.GetIssueCreateMetaIssueType(o, globals.Endpoint.Value, opts.Project, opts.IssueType)
if err != nil { if err != nil {
return err return err
} }
@@ -85,18 +82,18 @@ func CmdCreate(o *oreo.Client, opts *CreateOptions) error {
} }
input.Overrides["project"] = opts.Project input.Overrides["project"] = opts.Project
input.Overrides["issuetype"] = opts.IssueType input.Overrides["issuetype"] = opts.IssueType
input.Overrides["user"] = opts.User.Value input.Overrides["user"] = globals.User.Value
var issueResp *jiradata.IssueCreateResponse var issueResp *jiradata.IssueCreateResponse
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
issueResp, err = jira.CreateIssue(o, opts.Endpoint.Value, &issueUpdate) issueResp, err = jira.CreateIssue(o, globals.Endpoint.Value, &issueUpdate)
return err return err
}) })
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, opts.Endpoint.Value, issueResp.Key) 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)
@@ -106,7 +103,7 @@ func CmdCreate(o *oreo.Client, opts *CreateOptions) error {
defer fh.Close() defer fh.Close()
out, err := yaml.Marshal(map[string]string{ out, err := yaml.Marshal(map[string]string{
"issue": issueResp.Key, "issue": issueResp.Key,
"link": fmt.Sprintf("%s/browse/%s", opts.Endpoint.Value, issueResp.Key), "link": fmt.Sprintf("%s/browse/%s", globals.Endpoint.Value, issueResp.Key),
}) })
if err != nil { if err != nil {
return err return err
@@ -115,7 +112,7 @@ func CmdCreate(o *oreo.Client, opts *CreateOptions) error {
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, issueResp.Key}) return CmdBrowse(globals, issueResp.Key)
} }
return nil return nil
} }
+13 -16
View File
@@ -9,46 +9,43 @@ import (
) )
type CreateMetaOptions struct { type CreateMetaOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"` Project string `yaml:"project,omitempty" json:"project,omitempty"`
IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"` IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"`
} }
func CmdCreateMetaRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdCreateMetaRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := CreateMetaOptions{ opts := CreateMetaOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("createmeta"), Template: figtree.NewStringOption("createmeta"),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"View 'create' metadata", "View 'create' metadata",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdCreateMeta(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdCreateMetaUsage(cmd, &opts) return CmdCreateMetaUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdCreateMeta(o, globals, &opts)
},
} }
} }
func CmdCreateMetaUsage(cmd *kingpin.CmdClause, opts *CreateMetaOptions) error { func CmdCreateMetaUsage(cmd *kingpin.CmdClause, opts *CreateMetaOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.TemplateUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("project", "project to fetch create metadata").Short('p').StringVar(&opts.Project) cmd.Flag("project", "project to fetch create metadata").Short('p').StringVar(&opts.Project)
cmd.Flag("issuetype", "issuetype in project to fetch create metadata").Short('i').StringVar(&opts.IssueType) cmd.Flag("issuetype", "issuetype in project to fetch create metadata").Short('i').StringVar(&opts.IssueType)
return nil return nil
} }
// Create will get issue create metadata and send to "createmeta" template // Create will get issue create metadata and send to "createmeta" template
func CmdCreateMeta(o *oreo.Client, opts *CreateMetaOptions) error { func CmdCreateMeta(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateMetaOptions) error {
if err := defaultIssueType(o, opts.Endpoint.Value, &opts.Project, &opts.IssueType); err != nil { if err := defaultIssueType(o, globals.Endpoint.Value, &opts.Project, &opts.IssueType); err != nil {
return err return err
} }
createMeta, err := jira.GetIssueCreateMetaIssueType(o, opts.Endpoint.Value, opts.Project, opts.IssueType) createMeta, err := jira.GetIssueCreateMetaIssueType(o, globals.Endpoint.Value, opts.Project, opts.IssueType)
if err != nil { if err != nil {
return err return err
} }
+18 -21
View File
@@ -13,15 +13,15 @@ import (
) )
type DupOptions struct { type DupOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"` jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"`
Duplicate string `yaml:"duplicate,omitempty" json:"duplicate,omitempty"` Duplicate string `yaml:"duplicate,omitempty" json:"duplicate,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
} }
func CmdDupRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdDupRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := DupOptions{ opts := DupOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("edit"), Template: figtree.NewStringOption("edit"),
}, },
LinkIssueRequest: jiradata.LinkIssueRequest{ LinkIssueRequest: jiradata.LinkIssueRequest{
@@ -35,23 +35,20 @@ func CmdDupRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegist
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Mark issues as duplicate", "Mark issues as duplicate",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdDup(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdDupUsage(cmd, &opts) return CmdDupUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdDup(o, globals, &opts)
},
} }
} }
func CmdDupUsage(cmd *kingpin.CmdClause, opts *DupOptions) error { func CmdDupUsage(cmd *kingpin.CmdClause, opts *DupOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.EditorUsage(cmd, &opts.CommonOptions)
} jiracli.TemplateUsage(cmd, &opts.CommonOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("comment", "Comment message when marking issue as duplicate").Short('m').PreAction(func(ctx *kingpin.ParseContext) error { cmd.Flag("comment", "Comment message when marking issue as duplicate").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Comment = &jiradata.Comment{ opts.Comment = &jiradata.Comment{
Body: jiracli.FlagValue(ctx, "comment"), Body: jiracli.FlagValue(ctx, "comment"),
@@ -65,13 +62,13 @@ func CmdDupUsage(cmd *kingpin.CmdClause, opts *DupOptions) error {
// CmdDups will update the given issue as being a duplicate by the given dup issue // CmdDups will update the given issue as being a duplicate by the given dup issue
// and will attempt to resolve the dup issue // and will attempt to resolve the dup issue
func CmdDup(o *oreo.Client, opts *DupOptions) error { func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) error {
if err := jira.LinkIssues(o, opts.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, opts.Endpoint.Value, opts.OutwardIssue.Key) fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
meta, err := jira.GetIssueTransitions(o, opts.Endpoint.Value, opts.InwardIssue.Key) meta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key)
if err != nil { if err != nil {
return err return err
} }
@@ -81,7 +78,7 @@ func CmdDup(o *oreo.Client, opts *DupOptions) error {
issueUpdate := jiradata.IssueUpdate{ issueUpdate := jiradata.IssueUpdate{
Transition: transMeta, Transition: transMeta,
} }
if err = jira.TransitionIssue(o, opts.Endpoint.Value, opts.InwardIssue.Key, &issueUpdate); err != nil { if err = jira.TransitionIssue(o, globals.Endpoint.Value, opts.InwardIssue.Key, &issueUpdate); err != nil {
return err return err
} }
// if we just started the issue now we need to stop it // if we just started the issue now we need to stop it
@@ -91,11 +88,11 @@ func CmdDup(o *oreo.Client, opts *DupOptions) error {
} }
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, opts.Endpoint.Value, opts.InwardIssue.Key) 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(&BrowseOptions{opts.GlobalOptions, opts.OutwardIssue.Key}); err != nil { if err := CmdBrowse(globals, opts.OutwardIssue.Key); err != nil {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.InwardIssue.Key}) return CmdBrowse(globals, opts.InwardIssue.Key)
} }
} }
+27 -30
View File
@@ -13,16 +13,16 @@ import (
) )
type EditOptions struct { type EditOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"` jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"`
jira.SearchOptions `yaml:",inline" json:",inline" figtree:",inline"` jira.SearchOptions `yaml:",inline" json:",inline" figtree:",inline"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"` Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
} }
func CmdEditRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdEditRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := EditOptions{ opts := EditOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("edit"), Template: figtree.NewStringOption("edit"),
}, },
Overrides: map[string]string{}, Overrides: map[string]string{},
@@ -30,23 +30,20 @@ func CmdEditRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegis
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Edit issue details", "Edit issue details",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdEdit(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdEditUsage(cmd, &opts) return CmdEditUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdEdit(o, globals, &opts)
},
} }
} }
func CmdEditUsage(cmd *kingpin.CmdClause, opts *EditOptions) error { func CmdEditUsage(cmd *kingpin.CmdClause, opts *EditOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.EditorUsage(cmd, &opts.CommonOptions)
} jiracli.TemplateUsage(cmd, &opts.CommonOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing) cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("query", "Jira Query Language (JQL) expression for the search to edit multiple issues").Short('q').StringVar(&opts.Query) cmd.Flag("query", "Jira Query Language (JQL) expression for the search to edit multiple issues").Short('q').StringVar(&opts.Query)
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error { cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
@@ -59,18 +56,18 @@ func CmdEditUsage(cmd *kingpin.CmdClause, opts *EditOptions) error {
} }
// Edit will get issue data and send to "edit" template // Edit will get issue data and send to "edit" template
func CmdEdit(o *oreo.Client, opts *EditOptions) error { func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions) error {
type templateInput struct { type templateInput struct {
*jiradata.Issue `yaml:",inline"` *jiradata.Issue `yaml:",inline"`
Meta *jiradata.EditMeta `yaml:"meta" json:"meta"` Meta *jiradata.EditMeta `yaml:"meta" json:"meta"`
Overrides map[string]string `yaml:"overrides" json:"overrides"` Overrides map[string]string `yaml:"overrides" json:"overrides"`
} }
if opts.Issue != "" { if opts.Issue != "" {
issueData, err := jira.GetIssue(o, opts.Endpoint.Value, opts.Issue, nil) issueData, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, nil)
if err != nil { if err != nil {
return err return err
} }
editMeta, err := jira.GetIssueEditMeta(o, opts.Endpoint.Value, opts.Issue) editMeta, err := jira.GetIssueEditMeta(o, globals.Endpoint.Value, opts.Issue)
if err != nil { if err != nil {
return err return err
} }
@@ -81,24 +78,24 @@ func CmdEdit(o *oreo.Client, opts *EditOptions) error {
Meta: editMeta, Meta: editMeta,
Overrides: opts.Overrides, Overrides: opts.Overrides,
} }
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
return jira.EditIssue(o, opts.Endpoint.Value, opts.Issue, &issueUpdate) return jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate)
}) })
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue) 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(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
} }
results, err := jira.Search(o, opts.Endpoint.Value, opts) results, err := jira.Search(o, globals.Endpoint.Value, opts)
if err != nil { if err != nil {
return err return err
} }
for _, issueData := range results.Issues { for _, issueData := range results.Issues {
editMeta, err := jira.GetIssueEditMeta(o, opts.Endpoint.Value, issueData.Key) editMeta, err := jira.GetIssueEditMeta(o, globals.Endpoint.Value, issueData.Key)
if err != nil { if err != nil {
return err return err
} }
@@ -108,16 +105,16 @@ func CmdEdit(o *oreo.Client, opts *EditOptions) error {
Issue: issueData, Issue: issueData,
Meta: editMeta, Meta: editMeta,
} }
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
return jira.EditIssue(o, opts.Endpoint.Value, issueData.Key, &issueUpdate) return jira.EditIssue(o, globals.Endpoint.Value, issueData.Key, &issueUpdate)
}) })
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, opts.Endpoint.Value, issueData.Key) 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(&BrowseOptions{opts.GlobalOptions, issueData.Key}) return CmdBrowse(globals, issueData.Key)
} }
} }
return nil return nil
+13 -16
View File
@@ -9,43 +9,40 @@ import (
) )
type EditMetaOptions struct { type EditMetaOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
} }
func CmdEditMetaRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdEditMetaRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := EditMetaOptions{ opts := EditMetaOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("editmeta"), Template: figtree.NewStringOption("editmeta"),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"View 'edit' metadata", "View 'edit' metadata",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdEditMeta(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdEditMetaUsage(cmd, &opts) return CmdEditMetaUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdEditMeta(o, globals, &opts)
},
} }
} }
func CmdEditMetaUsage(cmd *kingpin.CmdClause, opts *EditMetaOptions) error { func CmdEditMetaUsage(cmd *kingpin.CmdClause, opts *EditMetaOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.TemplateUsage(cmd, &opts.CommonOptions)
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Arg("ISSUE", "edit metadata for issue id").Required().StringVar(&opts.Issue) cmd.Arg("ISSUE", "edit metadata for issue id").Required().StringVar(&opts.Issue)
return nil return nil
} }
// EditMeta will get issue edit metadata and send to "editmeta" template // EditMeta will get issue edit metadata and send to "editmeta" template
func CmdEditMeta(o *oreo.Client, opts *EditMetaOptions) error { func CmdEditMeta(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditMetaOptions) error {
editMeta, err := jira.GetIssueEditMeta(o, opts.Endpoint.Value, opts.Issue) editMeta, err := jira.GetIssueEditMeta(o, globals.Endpoint.Value, opts.Issue)
if err != nil { if err != nil {
return err return err
} }
@@ -53,7 +50,7 @@ func CmdEditMeta(o *oreo.Client, opts *EditMetaOptions) error {
return err return err
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
} }
+5 -5
View File
@@ -15,21 +15,21 @@ type ExportTemplatesOptions struct {
Dir string `yaml:"dir,omitempty" json:"dir,omitempty"` Dir string `yaml:"dir,omitempty" json:"dir,omitempty"`
} }
func CmdExportTemplatesRegistry(fig *figtree.FigTree) *jiracli.CommandRegistryEntry { func CmdExportTemplatesRegistry() *jiracli.CommandRegistryEntry {
opts := ExportTemplatesOptions{} opts := ExportTemplatesOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Export templates for customizations", "Export templates for customizations",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdExportTemplates(&opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
if opts.Dir == "" { if opts.Dir == "" {
opts.Dir = fmt.Sprintf("%s/.jira.d/templates", jiracli.Homedir()) opts.Dir = fmt.Sprintf("%s/.jira.d/templates", jiracli.Homedir())
} }
return CmdExportTemplatesUsage(cmd, &opts) return CmdExportTemplatesUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdExportTemplates(&opts)
},
} }
} }
+9 -10
View File
@@ -8,27 +8,26 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
func CmdFieldsRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdFieldsRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.GlobalOptions{ opts := jiracli.CommonOptions{
Template: figtree.NewStringOption("fields"), Template: figtree.NewStringOption("fields"),
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Prints all fields, both System and Custom", "Prints all fields, both System and Custom",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdFields(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
err := jiracli.GlobalUsage(cmd, &opts)
jiracli.TemplateUsage(cmd, &opts) jiracli.TemplateUsage(cmd, &opts)
return err return nil
},
func(globals *jiracli.GlobalOptions) error {
return CmdFields(o, globals, &opts)
}, },
} }
} }
// Fields will send data from /rest/api/2/field API to "fields" template // Fields will send data from /rest/api/2/field API to "fields" template
func CmdFields(o *oreo.Client, opts *jiracli.GlobalOptions) error { func CmdFields(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
data, err := jira.GetFields(o, opts.Endpoint.Value) data, err := jira.GetFields(o, globals.Endpoint.Value)
if err != nil { if err != nil {
return err return err
} }
+15 -18
View File
@@ -13,12 +13,12 @@ import (
) )
type IssueLinkOptions struct { type IssueLinkOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"` jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"`
LinkType string `yaml:"linktype,omitempty" json:"linktype,omitempty"` LinkType string `yaml:"linktype,omitempty" json:"linktype,omitempty"`
} }
func CmdIssueLinkRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdIssueLinkRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := IssueLinkOptions{ opts := IssueLinkOptions{
LinkIssueRequest: jiradata.LinkIssueRequest{ LinkIssueRequest: jiradata.LinkIssueRequest{
Type: &jiradata.IssueLinkType{}, Type: &jiradata.IssueLinkType{},
@@ -28,23 +28,20 @@ func CmdIssueLinkRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.Command
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Link two issues", "Link two issues",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdIssueLink(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdIssueLinkUsage(cmd, &opts) return CmdIssueLinkUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdIssueLink(o, globals, &opts)
},
} }
} }
func CmdIssueLinkUsage(cmd *kingpin.CmdClause, opts *IssueLinkOptions) error { func CmdIssueLinkUsage(cmd *kingpin.CmdClause, opts *IssueLinkOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.EditorUsage(cmd, &opts.CommonOptions)
} jiracli.TemplateUsage(cmd, &opts.CommonOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("comment", "Comment message when linking issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error { cmd.Flag("comment", "Comment message when linking issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Comment = &jiradata.Comment{ opts.Comment = &jiradata.Comment{
Body: jiracli.FlagValue(ctx, "comment"), Body: jiracli.FlagValue(ctx, "comment"),
@@ -59,17 +56,17 @@ func CmdIssueLinkUsage(cmd *kingpin.CmdClause, opts *IssueLinkOptions) error {
// CmdBlock will update the given issue as being a duplicate by the given dup issue // CmdBlock will update the given issue as being a duplicate by the given dup issue
// and will attempt to resolve the dup issue // and will attempt to resolve the dup issue
func CmdIssueLink(o *oreo.Client, opts *IssueLinkOptions) error { func CmdIssueLink(o *oreo.Client, globals *jiracli.GlobalOptions, opts *IssueLinkOptions) error {
if err := jira.LinkIssues(o, opts.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.InwardIssue.Key, opts.Endpoint.Value, opts.InwardIssue.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, opts.Endpoint.Value, opts.OutwardIssue.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(&BrowseOptions{opts.GlobalOptions, opts.OutwardIssue.Key}); err != nil { if err := CmdBrowse(globals, opts.OutwardIssue.Key); err != nil {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.InwardIssue.Key}) return CmdBrowse(globals, opts.InwardIssue.Key)
} }
} }
+9 -12
View File
@@ -8,34 +8,31 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
func CmdIssueLinkTypesRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdIssueLinkTypesRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.GlobalOptions{ opts := jiracli.CommonOptions{
Template: figtree.NewStringOption("issuelinktypes"), Template: figtree.NewStringOption("issuelinktypes"),
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Show the issue link types", "Show the issue link types",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdIssueLinkTypes(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdIssueLinkTypesUsage(cmd, &opts) return CmdIssueLinkTypesUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdIssueLinkTypes(o, globals, &opts)
},
} }
} }
func CmdIssueLinkTypesUsage(cmd *kingpin.CmdClause, opts *jiracli.GlobalOptions) error { func CmdIssueLinkTypesUsage(cmd *kingpin.CmdClause, opts *jiracli.CommonOptions) error {
if err := jiracli.GlobalUsage(cmd, opts); err != nil {
return err
}
jiracli.TemplateUsage(cmd, opts) jiracli.TemplateUsage(cmd, opts)
return nil return nil
} }
// CmdIssueLinkTypes will get issue link type data and send to "issuelinktypes" template // CmdIssueLinkTypes will get issue link type data and send to "issuelinktypes" template
func CmdIssueLinkTypes(o *oreo.Client, opts *jiracli.GlobalOptions) error { func CmdIssueLinkTypes(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
data, err := jira.GetIssueLinkTypes(o, opts.Endpoint.Value) data, err := jira.GetIssueLinkTypes(o, globals.Endpoint.Value)
if err != nil { if err != nil {
return err return err
} }
+11 -14
View File
@@ -12,45 +12,42 @@ import (
) )
type IssueTypesOptions struct { type IssueTypesOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"` Project string `yaml:"project,omitempty" json:"project,omitempty"`
} }
func CmdIssueTypesRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdIssueTypesRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := IssueTypesOptions{ opts := IssueTypesOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("issuetypes"), Template: figtree.NewStringOption("issuetypes"),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Show issue types for a project", "Show issue types for a project",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdIssueTypes(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdIssueTypesUsage(cmd, &opts) return CmdIssueTypesUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdIssueTypes(o, globals, &opts)
},
} }
} }
func CmdIssueTypesUsage(cmd *kingpin.CmdClause, opts *IssueTypesOptions) error { func CmdIssueTypesUsage(cmd *kingpin.CmdClause, opts *IssueTypesOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.TemplateUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("project", "project to list issueTypes").Short('p').StringVar(&opts.Project) cmd.Flag("project", "project to list issueTypes").Short('p').StringVar(&opts.Project)
return nil return nil
} }
// CmdIssueTypes will get available issueTypes for project and send to the "issueTypes" template // CmdIssueTypes will get available issueTypes for project and send to the "issueTypes" template
func CmdIssueTypes(o *oreo.Client, opts *IssueTypesOptions) error { func CmdIssueTypes(o *oreo.Client, globals *jiracli.GlobalOptions, opts *IssueTypesOptions) error {
if opts.Project == "" { if opts.Project == "" {
return fmt.Errorf("Project Required.") return fmt.Errorf("Project Required.")
} }
data, err := jira.GetIssueCreateMetaProject(o, opts.Endpoint.Value, opts.Project) data, err := jira.GetIssueCreateMetaProject(o, globals.Endpoint.Value, opts.Project)
if err != nil { if err != nil {
return err return err
} }
+13 -16
View File
@@ -13,37 +13,34 @@ import (
) )
type LabelsAddOptions struct { type LabelsAddOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"` Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
} }
func CmdLabelsAddRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdLabelsAddRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := LabelsAddOptions{} opts := LabelsAddOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Add labels to an issue", "Add labels to an issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdLabelsAdd(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdLabelsAddUsage(cmd, &opts) return CmdLabelsAddUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdLabelsAdd(o, globals, &opts)
},
} }
} }
func CmdLabelsAddUsage(cmd *kingpin.CmdClause, opts *LabelsAddOptions) error { func CmdLabelsAddUsage(cmd *kingpin.CmdClause, opts *LabelsAddOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue) cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue)
cmd.Arg("LABEL", "label to add to issue").Required().StringsVar(&opts.Labels) cmd.Arg("LABEL", "label to add to issue").Required().StringsVar(&opts.Labels)
return nil return nil
} }
// CmdLabels will add labels on a given issue // CmdLabels will add labels on a given issue
func CmdLabelsAdd(o *oreo.Client, opts *LabelsAddOptions) error { func CmdLabelsAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsAddOptions) error {
ops := jiradata.FieldOperations{} ops := jiradata.FieldOperations{}
for _, label := range opts.Labels { for _, label := range opts.Labels {
ops = append(ops, jiradata.FieldOperation{ ops = append(ops, jiradata.FieldOperation{
@@ -56,12 +53,12 @@ func CmdLabelsAdd(o *oreo.Client, opts *LabelsAddOptions) error {
}, },
} }
if err := jira.EditIssue(o, opts.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, opts.Endpoint.Value, opts.Issue) 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(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
} }
+13 -16
View File
@@ -13,37 +13,34 @@ import (
) )
type LabelsRemoveOptions struct { type LabelsRemoveOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"` Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
} }
func CmdLabelsRemoveRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdLabelsRemoveRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := LabelsRemoveOptions{} opts := LabelsRemoveOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Remove labels from an issue", "Remove labels from an issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdLabelsRemove(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdLabelsRemoveUsage(cmd, &opts) return CmdLabelsRemoveUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdLabelsRemove(o, globals, &opts)
},
} }
} }
func CmdLabelsRemoveUsage(cmd *kingpin.CmdClause, opts *LabelsRemoveOptions) error { func CmdLabelsRemoveUsage(cmd *kingpin.CmdClause, opts *LabelsRemoveOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue) cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue)
cmd.Arg("LABEL", "label to remove from issue").Required().StringsVar(&opts.Labels) cmd.Arg("LABEL", "label to remove from issue").Required().StringsVar(&opts.Labels)
return nil return nil
} }
// CmdLabels will remove labels on a given issue // CmdLabels will remove labels on a given issue
func CmdLabelsRemove(o *oreo.Client, opts *LabelsRemoveOptions) error { func CmdLabelsRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsRemoveOptions) error {
ops := jiradata.FieldOperations{} ops := jiradata.FieldOperations{}
for _, label := range opts.Labels { for _, label := range opts.Labels {
ops = append(ops, jiradata.FieldOperation{ ops = append(ops, jiradata.FieldOperation{
@@ -56,13 +53,13 @@ func CmdLabelsRemove(o *oreo.Client, opts *LabelsRemoveOptions) error {
}, },
} }
err := jira.EditIssue(o, opts.Endpoint.Value, opts.Issue, &issueUpdate) err := jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate)
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue) 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(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
} }
+13 -16
View File
@@ -13,37 +13,34 @@ import (
) )
type LabelsSetOptions struct { type LabelsSetOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"` Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
} }
func CmdLabelsSetRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdLabelsSetRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := LabelsSetOptions{} opts := LabelsSetOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Set labels on an issue", "Set labels on an issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdLabelsSet(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdLabelsSetUsage(cmd, &opts) return CmdLabelsSetUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdLabelsSet(o, globals, &opts)
},
} }
} }
func CmdLabelsSetUsage(cmd *kingpin.CmdClause, opts *LabelsSetOptions) error { func CmdLabelsSetUsage(cmd *kingpin.CmdClause, opts *LabelsSetOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue) cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue)
cmd.Arg("LABEL", "label to set on issue").Required().StringsVar(&opts.Labels) cmd.Arg("LABEL", "label to set on issue").Required().StringsVar(&opts.Labels)
return nil return nil
} }
// CmdLabels will set labels on a given issue // CmdLabels will set labels on a given issue
func CmdLabelsSet(o *oreo.Client, opts *LabelsSetOptions) error { func CmdLabelsSet(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsSetOptions) error {
issueUpdate := jiradata.IssueUpdate{ issueUpdate := jiradata.IssueUpdate{
Update: jiradata.FieldOperationsMap{ Update: jiradata.FieldOperationsMap{
"labels": jiradata.FieldOperations{ "labels": jiradata.FieldOperations{
@@ -54,12 +51,12 @@ func CmdLabelsSet(o *oreo.Client, opts *LabelsSetOptions) error {
}, },
} }
if err := jira.EditIssue(o, opts.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, opts.Endpoint.Value, opts.Issue) 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(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
} }
+11 -14
View File
@@ -9,23 +9,20 @@ import (
) )
type ListOptions struct { type ListOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jira.SearchOptions `yaml:",inline" json:",inline" figtree:",inline"` jira.SearchOptions `yaml:",inline" json:",inline" figtree:",inline"`
} }
func CmdListRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdListRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := ListOptions{ opts := ListOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("list"), Template: figtree.NewStringOption("list"),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Prints list of issues for given search criteria", "Prints list of issues for given search criteria",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdList(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
if opts.MaxResults == 0 { if opts.MaxResults == 0 {
opts.MaxResults = 500 opts.MaxResults = 500
@@ -38,14 +35,14 @@ func CmdListRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegis
} }
return CmdListUsage(cmd, &opts) return CmdListUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdList(o, globals, &opts)
},
} }
} }
func CmdListUsage(cmd *kingpin.CmdClause, opts *ListOptions) error { func CmdListUsage(cmd *kingpin.CmdClause, opts *ListOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.TemplateUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("assignee", "User assigned the issue").Short('a').StringVar(&opts.Assignee) cmd.Flag("assignee", "User assigned the issue").Short('a').StringVar(&opts.Assignee)
cmd.Flag("component", "Component to search for").Short('c').StringVar(&opts.Component) cmd.Flag("component", "Component to search for").Short('c').StringVar(&opts.Component)
cmd.Flag("issuetype", "Issue type to search for").Short('i').StringVar(&opts.IssueType) cmd.Flag("issuetype", "Issue type to search for").Short('i').StringVar(&opts.IssueType)
@@ -60,8 +57,8 @@ func CmdListUsage(cmd *kingpin.CmdClause, opts *ListOptions) error {
} }
// List will query jira and send data to "list" template // List will query jira and send data to "list" template
func CmdList(o *oreo.Client, opts *ListOptions) error { func CmdList(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ListOptions) error {
data, err := jira.Search(o, opts.Endpoint.Value, opts) data, err := jira.Search(o, globals.Endpoint.Value, opts)
if err != nil { if err != nil {
return err return err
} }
+12 -12
View File
@@ -12,16 +12,16 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
func CmdLoginRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdLoginRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.GlobalOptions{} opts := jiracli.CommonOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Attempt to login into jira server", "Attempt to login into jira server",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdLogin(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return jiracli.GlobalUsage(cmd, &opts) return nil
},
func(globals *jiracli.GlobalOptions) error {
return CmdLogin(o, globals, &opts)
}, },
} }
} }
@@ -45,19 +45,19 @@ func authCallback(req *http.Request, resp *http.Response) (*http.Response, error
} }
// CmdLogin will attempt to login into jira server // CmdLogin will attempt to login into jira server
func CmdLogin(o *oreo.Client, opts *jiracli.GlobalOptions) error { func CmdLogin(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks().WithPostCallback(authCallback) ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks().WithPostCallback(authCallback)
for { for {
if session, err := jira.GetSession(o, opts.Endpoint.Value); err != nil { if session, err := jira.GetSession(o, globals.Endpoint.Value); err != nil {
// No active session so try to create a new one // No active session so try to create a new one
_, err := jira.NewSession(ua, opts.Endpoint.Value, opts) _, err := jira.NewSession(ua, globals.Endpoint.Value, globals)
if err != nil { if err != nil {
// reset password on failed session // reset password on failed session
opts.SetPass("") globals.SetPass("")
log.Errorf("%s", err) log.Errorf("%s", err)
continue continue
} }
fmt.Println(ansi.Color("OK", "green"), "New session for", opts.User) 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) fmt.Println(ansi.Color("OK", "green"), "Found session for", session.Name)
+11 -11
View File
@@ -11,28 +11,28 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
func CmdLogoutRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdLogoutRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := jiracli.GlobalOptions{} opts := jiracli.CommonOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Deactivate sesssion with Jira server", "Deactivate sesssion with Jira server",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdLogout(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return jiracli.GlobalUsage(cmd, &opts) return nil
},
func(globals *jiracli.GlobalOptions) error {
return CmdLogout(o, globals, &opts)
}, },
} }
} }
// CmdLogout will attempt to terminate an active Jira session // CmdLogout will attempt to terminate an active Jira session
func CmdLogout(o *oreo.Client, opts *jiracli.GlobalOptions) error { func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks() ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks()
err := jira.DeleteSession(ua, opts.Endpoint.Value) err := jira.DeleteSession(ua, globals.Endpoint.Value)
if err == nil { if err == nil {
fmt.Println(ansi.Color("OK", "green"), "Terminated session for", opts.User) 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"), opts.User, err) fmt.Printf("%s Failed to terminate session for %s: %s", ansi.Color("ERROR", "red"), globals.User, err)
} }
return nil return nil
} }
+16 -19
View File
@@ -13,32 +13,29 @@ import (
) )
type RankOptions struct { type RankOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
First string `yaml:"first,omitempty" json:"first,omitempty"` First string `yaml:"first,omitempty" json:"first,omitempty"`
Second string `yaml:"second,omitempty" json:"second,omitempty"` Second string `yaml:"second,omitempty" json:"second,omitempty"`
Order string `yaml:"order,omitempty" json:"order,omitempty"` Order string `yaml:"order,omitempty" json:"order,omitempty"`
} }
func CmdRankRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdRankRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := RankOptions{} opts := RankOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Mark issues as blocker", "Mark issues as blocker",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdRank(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdRankUsage(cmd, &opts) return CmdRankUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdRank(o, globals, &opts)
},
} }
} }
func CmdRankUsage(cmd *kingpin.CmdClause, opts *RankOptions) error { func CmdRankUsage(cmd *kingpin.CmdClause, opts *RankOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
cmd.Arg("FIRST-ISSUE", "first issue").Required().StringVar(&opts.First) cmd.Arg("FIRST-ISSUE", "first issue").Required().StringVar(&opts.First)
cmd.Arg("after|before", "rank ordering").Required().HintOptions("after", "before").EnumVar(&opts.Order, "after", "before") cmd.Arg("after|before", "rank ordering").Required().HintOptions("after", "before").EnumVar(&opts.Order, "after", "before")
cmd.Arg("SECOND-ISSUE", "second issue").Required().StringVar(&opts.Second) cmd.Arg("SECOND-ISSUE", "second issue").Required().StringVar(&opts.Second)
@@ -46,7 +43,7 @@ func CmdRankUsage(cmd *kingpin.CmdClause, opts *RankOptions) error {
} }
// CmdRank order two issue // CmdRank order two issue
func CmdRank(o *oreo.Client, opts *RankOptions) error { func CmdRank(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RankOptions) error {
req := &jiradata.RankRequest{ req := &jiradata.RankRequest{
Issues: []string{opts.First}, Issues: []string{opts.First},
} }
@@ -57,16 +54,16 @@ func CmdRank(o *oreo.Client, opts *RankOptions) error {
req.RankBeforeIssue = opts.Second req.RankBeforeIssue = opts.Second
} }
if err := jira.RankIssues(o, opts.Endpoint.Value, req); err != nil { if err := jira.RankIssues(o, globals.Endpoint.Value, req); err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.First, opts.Endpoint.Value, opts.First) 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, opts.Endpoint.Value, opts.Second) 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(&BrowseOptions{opts.GlobalOptions, opts.First}); err != nil { if err := CmdBrowse(globals, opts.First); err != nil {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Second}) return CmdBrowse(globals, opts.Second)
} }
} }
+9 -12
View File
@@ -15,38 +15,35 @@ import (
) )
type RequestOptions struct { type RequestOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Method string `yaml:"method,omitempty" json:"method,omitempty"` Method string `yaml:"method,omitempty" json:"method,omitempty"`
URI string `yaml:"uri,omitempty" json:"uri,omitempty"` URI string `yaml:"uri,omitempty" json:"uri,omitempty"`
Data string `yaml:"data,omitempty" json:"data,omitempty"` Data string `yaml:"data,omitempty" json:"data,omitempty"`
} }
func CmdRequestRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdRequestRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := RequestOptions{ opts := RequestOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("request"), Template: figtree.NewStringOption("request"),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Open issue in requestr", "Open issue in requestr",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdRequest(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
if opts.Method == "" { if opts.Method == "" {
opts.Method = "GET" opts.Method = "GET"
} }
return CmdRequestUsage(cmd, &opts) return CmdRequestUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdRequest(o, globals, &opts)
},
} }
} }
func CmdRequestUsage(cmd *kingpin.CmdClause, opts *RequestOptions) error { func CmdRequestUsage(cmd *kingpin.CmdClause, opts *RequestOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
cmd.Flag("method", "HTTP request method to use").Short('m').EnumVar(&opts.Method, "GET", "PUT", "POST", "DELETE") cmd.Flag("method", "HTTP request method to use").Short('m').EnumVar(&opts.Method, "GET", "PUT", "POST", "DELETE")
cmd.Arg("API", "Path to Jira API (ie: /rest/api/2/issue)").Required().StringVar(&opts.URI) cmd.Arg("API", "Path to Jira API (ie: /rest/api/2/issue)").Required().StringVar(&opts.URI)
cmd.Arg("JSON", "JSON Content to send to API").Required().StringVar(&opts.Data) cmd.Arg("JSON", "JSON Content to send to API").Required().StringVar(&opts.Data)
@@ -55,10 +52,10 @@ func CmdRequestUsage(cmd *kingpin.CmdClause, opts *RequestOptions) error {
} }
// CmdRequest open the default system requestr to the provided issue // CmdRequest open the default system requestr to the provided issue
func CmdRequest(o *oreo.Client, opts *RequestOptions) error { func CmdRequest(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RequestOptions) error {
uri := opts.URI uri := opts.URI
if !strings.HasPrefix(uri, "http") { if !strings.HasPrefix(uri, "http") {
uri = opts.Endpoint.Value + uri uri = globals.Endpoint.Value + uri
} }
parsedURI, err := url.Parse(uri) parsedURI, err := url.Parse(uri)
+23 -26
View File
@@ -13,17 +13,17 @@ import (
) )
type SubtaskOptions struct { type SubtaskOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"` jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"`
Project string `yaml:"project,omitempty" json:"project,omitempty"` Project string `yaml:"project,omitempty" json:"project,omitempty"`
IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"` IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"` Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
} }
func CmdSubtaskRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdSubtaskRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := SubtaskOptions{ opts := SubtaskOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("subtask"), Template: figtree.NewStringOption("subtask"),
}, },
Overrides: map[string]string{}, Overrides: map[string]string{},
@@ -31,26 +31,23 @@ func CmdSubtaskRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRe
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Subtask issue", "Subtask issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdSubtask(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
if opts.IssueType == "" { if opts.IssueType == "" {
opts.IssueType = "Sub-task" opts.IssueType = "Sub-task"
} }
return CmdSubtaskUsage(cmd, &opts) return CmdSubtaskUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdSubtask(o, globals, &opts)
},
} }
} }
func CmdSubtaskUsage(cmd *kingpin.CmdClause, opts *SubtaskOptions) error { func CmdSubtaskUsage(cmd *kingpin.CmdClause, opts *SubtaskOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.EditorUsage(cmd, &opts.CommonOptions)
} jiracli.TemplateUsage(cmd, &opts.CommonOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing) cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("project", "project to subtask issue in").Short('p').StringVar(&opts.Project) cmd.Flag("project", "project to subtask issue in").Short('p').StringVar(&opts.Project)
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error { cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
@@ -64,14 +61,14 @@ func CmdSubtaskUsage(cmd *kingpin.CmdClause, opts *SubtaskOptions) error {
// CmdSubtask sends the subtask-metadata to the "subtask" template for editing, then // CmdSubtask sends the subtask-metadata to the "subtask" template for editing, then
// will parse the edited document as YAML and submit the document to jira. // will parse the edited document as YAML and submit the document to jira.
func CmdSubtask(o *oreo.Client, opts *SubtaskOptions) error { func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOptions) error {
type templateInput struct { type templateInput struct {
Meta *jiradata.IssueType `yaml:"meta" json:"meta"` Meta *jiradata.IssueType `yaml:"meta" json:"meta"`
Overrides map[string]string `yaml:"overrides" json:"overrides"` Overrides map[string]string `yaml:"overrides" json:"overrides"`
Parent *jiradata.Issue `yaml:"parent" json:"parent"` Parent *jiradata.Issue `yaml:"parent" json:"parent"`
} }
parent, err := jira.GetIssue(o, opts.Endpoint.Value, opts.Issue, nil) parent, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, nil)
if err != nil { if err != nil {
return err return err
} }
@@ -86,7 +83,7 @@ func CmdSubtask(o *oreo.Client, opts *SubtaskOptions) error {
return fmt.Errorf("Failed to find Project field in parent issue") return fmt.Errorf("Failed to find Project field in parent issue")
} }
createMeta, err := jira.GetIssueCreateMetaIssueType(o, opts.Endpoint.Value, opts.Project, opts.IssueType) createMeta, err := jira.GetIssueCreateMetaIssueType(o, globals.Endpoint.Value, opts.Project, opts.IssueType)
if err != nil { if err != nil {
return err return err
} }
@@ -99,21 +96,21 @@ func CmdSubtask(o *oreo.Client, opts *SubtaskOptions) error {
} }
input.Overrides["project"] = opts.Project input.Overrides["project"] = opts.Project
input.Overrides["issuetype"] = opts.IssueType input.Overrides["issuetype"] = opts.IssueType
input.Overrides["user"] = opts.User.Value input.Overrides["user"] = globals.User.Value
var issueResp *jiradata.IssueCreateResponse var issueResp *jiradata.IssueCreateResponse
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
issueResp, err = jira.CreateIssue(o, opts.Endpoint.Value, &issueUpdate) issueResp, err = jira.CreateIssue(o, globals.Endpoint.Value, &issueUpdate)
return err return err
}) })
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, opts.Endpoint.Value, issueResp.Key) 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(&BrowseOptions{opts.GlobalOptions, issueResp.Key}) return CmdBrowse(globals, issueResp.Key)
} }
return nil return nil
} }
+7 -10
View File
@@ -7,27 +7,24 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
func CmdTakeRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdTakeRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := AssignOptions{} opts := AssignOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Assign issue to yourself", "Assign issue to yourself",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
opts.Assignee = opts.User.Value
return CmdAssign(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdAssignUsage(cmd, &opts) return CmdAssignUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
opts.Assignee = globals.User.Value
return CmdAssign(o, globals, &opts)
},
} }
} }
func CmdTakeUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error { func CmdTakeUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
cmd.Arg("ISSUE", "issue to assign").Required().StringVar(&opts.Issue) cmd.Arg("ISSUE", "issue to assign").Required().StringVar(&opts.Issue)
return nil return nil
} }
+20 -23
View File
@@ -14,16 +14,16 @@ import (
) )
type TransitionOptions struct { type TransitionOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"` Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Transition string `yaml:"transition,omitempty" json:"transition,omitempty"` Transition string `yaml:"transition,omitempty" json:"transition,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Resolution string `yaml:"resolution,omitempty" json:"resolution,omitempty"` Resolution string `yaml:"resolution,omitempty" json:"resolution,omitempty"`
} }
func CmdTransitionRegistry(fig *figtree.FigTree, o *oreo.Client, transition string) *jiracli.CommandRegistryEntry { func CmdTransitionRegistry(o *oreo.Client, transition string) *jiracli.CommandRegistryEntry {
opts := TransitionOptions{ opts := TransitionOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("transition"), Template: figtree.NewStringOption("transition"),
}, },
Overrides: map[string]string{}, Overrides: map[string]string{},
@@ -37,25 +37,22 @@ func CmdTransitionRegistry(fig *figtree.FigTree, o *oreo.Client, transition stri
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
help, help,
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdTransition(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
if opts.Transition == "" { if opts.Transition == "" {
opts.Transition = transition opts.Transition = transition
} }
return CmdTransitionUsage(cmd, &opts) return CmdTransitionUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdTransition(o, globals, &opts)
},
} }
} }
func CmdTransitionUsage(cmd *kingpin.CmdClause, opts *TransitionOptions) error { func CmdTransitionUsage(cmd *kingpin.CmdClause, opts *TransitionOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.TemplateUsage(cmd, &opts.CommonOptions)
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing) cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error { cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment") opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment")
@@ -70,13 +67,13 @@ func CmdTransitionUsage(cmd *kingpin.CmdClause, opts *TransitionOptions) error {
} }
// CmdTransition will move state of the given issue to the given transtion // CmdTransition will move state of the given issue to the given transtion
func CmdTransition(o *oreo.Client, opts *TransitionOptions) error { func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *TransitionOptions) error {
issueData, err := jira.GetIssue(o, opts.Endpoint.Value, opts.Issue, nil) issueData, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, nil)
if err != nil { if err != nil {
return jiracli.CliError(err) return jiracli.CliError(err)
} }
meta, err := jira.GetIssueTransitions(o, opts.Endpoint.Value, opts.Issue) meta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.Issue)
if err != nil { if err != nil {
return jiracli.CliError(err) return jiracli.CliError(err)
} }
@@ -128,16 +125,16 @@ func CmdTransition(o *oreo.Client, opts *TransitionOptions) error {
Transition: transMeta, Transition: transMeta,
Overrides: opts.Overrides, Overrides: opts.Overrides,
} }
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
return jira.TransitionIssue(o, opts.Endpoint.Value, opts.Issue, &issueUpdate) return jira.TransitionIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate)
}) })
if err != nil { if err != nil {
return jiracli.CliError(err) return jiracli.CliError(err)
} }
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, opts.Endpoint.Value, issueData.Key) 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(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
} }
+13 -16
View File
@@ -9,42 +9,39 @@ import (
) )
type TransitionsOptions struct { type TransitionsOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
} }
func CmdTransitionsRegistry(fig *figtree.FigTree, o *oreo.Client, defaultTemplate string) *jiracli.CommandRegistryEntry { func CmdTransitionsRegistry(o *oreo.Client, defaultTemplate string) *jiracli.CommandRegistryEntry {
opts := TransitionsOptions{ opts := TransitionsOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption(defaultTemplate), Template: figtree.NewStringOption(defaultTemplate),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"List valid issue transitions", "List valid issue transitions",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdTransitions(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdTransitionsUsage(cmd, &opts) return CmdTransitionsUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdTransitions(o, globals, &opts)
},
} }
} }
func CmdTransitionsUsage(cmd *kingpin.CmdClause, opts *TransitionsOptions) error { func CmdTransitionsUsage(cmd *kingpin.CmdClause, opts *TransitionsOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.TemplateUsage(cmd, &opts.CommonOptions)
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Arg("ISSUE", "issue to list valid transitions").Required().StringVar(&opts.Issue) cmd.Arg("ISSUE", "issue to list valid transitions").Required().StringVar(&opts.Issue)
return nil return nil
} }
// Transitions will get issue edit metadata and send to "editmeta" template // Transitions will get issue edit metadata and send to "editmeta" template
func CmdTransitions(o *oreo.Client, opts *TransitionsOptions) error { func CmdTransitions(o *oreo.Client, globals *jiracli.GlobalOptions, opts *TransitionsOptions) error {
editMeta, err := jira.GetIssueTransitions(o, opts.Endpoint.Value, opts.Issue) editMeta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.Issue)
if err != nil { if err != nil {
return err return err
} }
@@ -52,7 +49,7 @@ func CmdTransitions(o *oreo.Client, opts *TransitionsOptions) error {
return err return err
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
} }
+6 -9
View File
@@ -7,26 +7,23 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
func CmdUnassignRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdUnassignRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := AssignOptions{} opts := AssignOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Unassign an issue", "Unassign an issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdAssign(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdAssignUsage(cmd, &opts) return CmdAssignUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdAssign(o, globals, &opts)
},
} }
} }
func CmdUnassignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error { func CmdUnassignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
cmd.Arg("ISSUE", "issue to unassign").Required().StringVar(&opts.Issue) cmd.Arg("ISSUE", "issue to unassign").Required().StringVar(&opts.Issue)
return nil return nil
} }
+5 -5
View File
@@ -12,15 +12,12 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
func CmdUnexportTemplatesRegistry(fig *figtree.FigTree) *jiracli.CommandRegistryEntry { func CmdUnexportTemplatesRegistry() *jiracli.CommandRegistryEntry {
opts := ExportTemplatesOptions{} opts := ExportTemplatesOptions{}
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Remove unmodified exported templates", "Remove unmodified exported templates",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdUnexportTemplates(&opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
if opts.Dir != "" { if opts.Dir != "" {
opts.Dir = fmt.Sprintf("%s/.jira.d/templates", jiracli.Homedir()) opts.Dir = fmt.Sprintf("%s/.jira.d/templates", jiracli.Homedir())
@@ -28,6 +25,9 @@ func CmdUnexportTemplatesRegistry(fig *figtree.FigTree) *jiracli.CommandRegistry
return CmdExportTemplatesUsage(cmd, &opts) return CmdExportTemplatesUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdUnexportTemplates(&opts)
},
} }
} }
+14 -17
View File
@@ -9,36 +9,33 @@ import (
) )
type ViewOptions struct { type ViewOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jira.IssueOptions `yaml:",inline" json:",inline" figtree:",inline"` jira.IssueOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
} }
func CmdViewRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdViewRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := ViewOptions{ opts := ViewOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("view"), Template: figtree.NewStringOption("view"),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Prints issue details", "Prints issue details",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdView(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdViewUsage(cmd, &opts) return CmdViewUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdView(o, globals, &opts)
},
} }
} }
func CmdViewUsage(cmd *kingpin.CmdClause, opts *ViewOptions) error { func CmdViewUsage(cmd *kingpin.CmdClause, opts *ViewOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.TemplateUsage(cmd, &opts.CommonOptions)
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("expand", "field to expand for the issue").StringsVar(&opts.Expand) cmd.Flag("expand", "field to expand for the issue").StringsVar(&opts.Expand)
cmd.Flag("field", "field to return for the issue").StringsVar(&opts.Fields) cmd.Flag("field", "field to return for the issue").StringsVar(&opts.Fields)
cmd.Flag("property", "property to return for issue").StringsVar(&opts.Properties) cmd.Flag("property", "property to return for issue").StringsVar(&opts.Properties)
@@ -47,8 +44,8 @@ func CmdViewUsage(cmd *kingpin.CmdClause, opts *ViewOptions) error {
} }
// View will get issue data and send to "view" template // View will get issue data and send to "view" template
func CmdView(o *oreo.Client, opts *ViewOptions) error { func CmdView(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ViewOptions) error {
data, err := jira.GetIssue(o, opts.Endpoint.Value, opts.Issue, opts) data, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, opts)
if err != nil { if err != nil {
return err return err
} }
@@ -56,7 +53,7 @@ func CmdView(o *oreo.Client, opts *ViewOptions) error {
return err return err
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
} }
+15 -18
View File
@@ -19,34 +19,31 @@ const (
) )
type VoteOptions struct { type VoteOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Action VoteAction `yaml:"-" json:"-"` Action VoteAction `yaml:"-" json:"-"`
} }
func CmdVoteRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdVoteRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := VoteOptions{ opts := VoteOptions{
GlobalOptions: jiracli.GlobalOptions{}, CommonOptions: jiracli.CommonOptions{},
Action: VoteUP, Action: VoteUP,
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Vote up/down an issue", "Vote up/down an issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdVote(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdVoteUsage(cmd, &opts) return CmdVoteUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdVote(o, globals, &opts)
},
} }
} }
func CmdVoteUsage(cmd *kingpin.CmdClause, opts *VoteOptions) error { func CmdVoteUsage(cmd *kingpin.CmdClause, opts *VoteOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
cmd.Flag("down", "downvote the issue").Short('d').PreAction(func(ctx *kingpin.ParseContext) error { cmd.Flag("down", "downvote the issue").Short('d').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Action = VoteDown opts.Action = VoteDown
return nil return nil
@@ -56,20 +53,20 @@ func CmdVoteUsage(cmd *kingpin.CmdClause, opts *VoteOptions) error {
} }
// Vote will up/down vote an issue // Vote will up/down vote an issue
func CmdVote(o *oreo.Client, opts *VoteOptions) error { func CmdVote(o *oreo.Client, globals *jiracli.GlobalOptions, opts *VoteOptions) error {
if opts.Action == VoteUP { if opts.Action == VoteUP {
if err := jira.IssueAddVote(o, opts.Endpoint.Value, opts.Issue); err != nil { if err := jira.IssueAddVote(o, globals.Endpoint.Value, opts.Issue); err != nil {
return err return err
} }
} else { } else {
if err := jira.IssueRemoveVote(o, opts.Endpoint.Value, opts.Issue); err != nil { if err := jira.IssueRemoveVote(o, globals.Endpoint.Value, opts.Issue); err != nil {
return err return err
} }
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue) 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(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
} }
+17 -20
View File
@@ -19,35 +19,32 @@ const (
) )
type WatchOptions struct { type WatchOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Watcher string `yaml:"watcher,omitempty" json:"watcher,omitempty"` Watcher string `yaml:"watcher,omitempty" json:"watcher,omitempty"`
Action WatchAction `yaml:"-" json:"-"` Action WatchAction `yaml:"-" json:"-"`
} }
func CmdWatchRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdWatchRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := WatchOptions{ opts := WatchOptions{
GlobalOptions: jiracli.GlobalOptions{}, CommonOptions: jiracli.CommonOptions{},
Action: WatcherAdd, Action: WatcherAdd,
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Add/Remove watcher to issue", "Add/Remove watcher to issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdWatch(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdWatchUsage(cmd, &opts) return CmdWatchUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdWatch(o, globals, &opts)
},
} }
} }
func CmdWatchUsage(cmd *kingpin.CmdClause, opts *WatchOptions) error { func CmdWatchUsage(cmd *kingpin.CmdClause, opts *WatchOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
cmd.Flag("remove", "remove watcher from issue").Short('r').PreAction(func(ctx *kingpin.ParseContext) error { cmd.Flag("remove", "remove watcher from issue").Short('r').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Action = WatcherRemove opts.Action = WatcherRemove
return nil return nil
@@ -59,24 +56,24 @@ func CmdWatchUsage(cmd *kingpin.CmdClause, opts *WatchOptions) error {
// CmdWatch will add the given watcher to the issue (or remove the watcher // CmdWatch will add the given watcher to the issue (or remove the watcher
// with the 'remove' flag) // with the 'remove' flag)
func CmdWatch(o *oreo.Client, opts *WatchOptions) error { func CmdWatch(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WatchOptions) error {
if opts.Watcher == "" { if opts.Watcher == "" {
opts.Watcher = opts.User.Value opts.Watcher = globals.User.Value
} }
if opts.Action == WatcherAdd { if opts.Action == WatcherAdd {
if err := jira.IssueAddWatcher(o, opts.Endpoint.Value, opts.Issue, opts.Watcher); err != nil { if err := jira.IssueAddWatcher(o, globals.Endpoint.Value, opts.Issue, opts.Watcher); err != nil {
return err return err
} }
} else { } else {
if err := jira.IssueRemoveWatcher(o, opts.Endpoint.Value, opts.Issue, opts.Watcher); err != nil { if err := jira.IssueRemoveWatcher(o, globals.Endpoint.Value, opts.Issue, opts.Watcher); err != nil {
return err return err
} }
} }
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue) 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(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
+16 -19
View File
@@ -10,36 +10,33 @@ import (
) )
type WorklogAddOptions struct { type WorklogAddOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.Worklog `yaml:",inline" json:",inline" figtree:",inline"` jiradata.Worklog `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
} }
func CmdWorklogAddRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdWorklogAddRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := WorklogAddOptions{ opts := WorklogAddOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("worklog"), Template: figtree.NewStringOption("worklog"),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Add a worklog to an issue", "Add a worklog to an issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdWorklogAdd(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdWorklogAddUsage(cmd, &opts) return CmdWorklogAddUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdWorklogAdd(o, globals, &opts)
},
} }
} }
func CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOptions) error { func CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.EditorUsage(cmd, &opts.CommonOptions)
} jiracli.TemplateUsage(cmd, &opts.CommonOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing) cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
cmd.Flag("comment", "Comment message for worklog").Short('m').StringVar(&opts.Comment) cmd.Flag("comment", "Comment message for worklog").Short('m').StringVar(&opts.Comment)
cmd.Flag("time-spent", "Time spent working on issue").Short('T').StringVar(&opts.TimeSpent) cmd.Flag("time-spent", "Time spent working on issue").Short('T').StringVar(&opts.TimeSpent)
@@ -50,16 +47,16 @@ func CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOptions) error {
// CmdWorklogAdd will attempt to add (action=add) a worklog to the given issue. // CmdWorklogAdd will attempt to add (action=add) a worklog to the given issue.
// It will spawn the editor (unless --noedit isused) and post edited YAML // It will spawn the editor (unless --noedit isused) and post edited YAML
// content as JSON to the worklog endpoint // content as JSON to the worklog endpoint
func CmdWorklogAdd(o *oreo.Client, opts *WorklogAddOptions) error { func CmdWorklogAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WorklogAddOptions) error {
err := jiracli.EditLoop(&opts.GlobalOptions, &opts.Worklog, &opts.Worklog, func() error { err := jiracli.EditLoop(&opts.CommonOptions, &opts.Worklog, &opts.Worklog, func() error {
_, err := jira.AddIssueWorklog(o, opts.Endpoint.Value, opts.Issue, opts) _, err := jira.AddIssueWorklog(o, globals.Endpoint.Value, opts.Issue, opts)
return err return err
}) })
if err != nil { if err != nil {
return err return err
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
} }
+13 -16
View File
@@ -9,41 +9,38 @@ import (
) )
type WorklogListOptions struct { type WorklogListOptions struct {
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
} }
func CmdWorklogListRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { func CmdWorklogListRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := WorklogListOptions{ opts := WorklogListOptions{
GlobalOptions: jiracli.GlobalOptions{ CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("worklogs"), Template: figtree.NewStringOption("worklogs"),
}, },
} }
return &jiracli.CommandRegistryEntry{ return &jiracli.CommandRegistryEntry{
"Prints the worklog data for given issue", "Prints the worklog data for given issue",
func() error { func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
return CmdWorklogList(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts) jiracli.LoadConfigs(cmd, fig, &opts)
return CmdWorklogListUsage(cmd, &opts) return CmdWorklogListUsage(cmd, &opts)
}, },
func(globals *jiracli.GlobalOptions) error {
return CmdWorklogList(o, globals, &opts)
},
} }
} }
func CmdWorklogListUsage(cmd *kingpin.CmdClause, opts *WorklogListOptions) error { func CmdWorklogListUsage(cmd *kingpin.CmdClause, opts *WorklogListOptions) error {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { jiracli.BrowseUsage(cmd, &opts.CommonOptions)
return err jiracli.TemplateUsage(cmd, &opts.CommonOptions)
}
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Arg("ISSUE", "issue id to fetch worklogs").Required().StringVar(&opts.Issue) cmd.Arg("ISSUE", "issue id to fetch worklogs").Required().StringVar(&opts.Issue)
return nil return nil
} }
// // CmdWorklogList will get worklog data for given issue and sent to the "worklogs" template // // CmdWorklogList will get worklog data for given issue and sent to the "worklogs" template
func CmdWorklogList(o *oreo.Client, opts *WorklogListOptions) error { func CmdWorklogList(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WorklogListOptions) error {
data, err := jira.GetIssueWorklog(o, opts.Endpoint.Value, opts.Issue) data, err := jira.GetIssueWorklog(o, globals.Endpoint.Value, opts.Issue)
if err != nil { if err != nil {
return err return err
} }
@@ -51,7 +48,7 @@ func CmdWorklogList(o *oreo.Client, opts *WorklogListOptions) error {
return err return err
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue}) return CmdBrowse(globals, opts.Issue)
} }
return nil return nil
} }