diff --git a/jiracli/cli.go b/jiracli/cli.go index 8d8355a7..a9c96995 100644 --- a/jiracli/cli.go +++ b/jiracli/cli.go @@ -187,7 +187,7 @@ func (o *GlobalOptions) editFile(fileName string) (changes bool, err error) { return false, err } -func editLoop(opts *GlobalOptions, input interface{}, output interface{}, submit func() error) error { +func EditLoop(opts *GlobalOptions, input interface{}, output interface{}, submit func() error) error { tmpFile, err := tmpTemplate(opts.Template.Value, input) if err != nil { return err diff --git a/jiracli/error.go b/jiracli/error.go index 74dd1eb7..d247e8f2 100644 --- a/jiracli/error.go +++ b/jiracli/error.go @@ -6,7 +6,7 @@ type Error struct { error } -func cliError(cause error) error { +func CliError(cause error) error { return &Error{ errors.WithStack(cause), } diff --git a/jiracli/fields.go b/jiracli/fields.go deleted file mode 100644 index 4c506a1d..00000000 --- a/jiracli/fields.go +++ /dev/null @@ -1,35 +0,0 @@ -package jiracli - -import ( - "github.com/coryb/figtree" - "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" - kingpin "gopkg.in/alecthomas/kingpin.v2" -) - -func CmdFieldsRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { - opts := GlobalOptions{ - Template: figtree.NewStringOption("fields"), - } - return &CommandRegistryEntry{ - "Prints all fields, both System and Custom", - func() error { - return CmdFields(o, &opts) - }, - func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) - err := GlobalUsage(cmd, &opts) - TemplateUsage(cmd, &opts) - return err - }, - } -} - -// Fields will send data from /rest/api/2/field API to "fields" template -func CmdFields(o *oreo.Client, opts *GlobalOptions) error { - data, err := jira.GetFields(o, opts.Endpoint.Value) - if err != nil { - return err - } - return runTemplate(opts.Template.Value, data, nil) -} diff --git a/jiracli/templates.go b/jiracli/templates.go index e4d08c08..f4a20ab2 100644 --- a/jiracli/templates.go +++ b/jiracli/templates.go @@ -44,7 +44,7 @@ func getTemplate(name string) (string, error) { } else if b != nil { return string(b), nil } - if s, ok := allTemplates[name]; ok { + if s, ok := AllTemplates[name]; ok { return s, nil } return "", fmt.Errorf("No Template found for %q", name) @@ -56,7 +56,7 @@ func tmpTemplate(templateName string, data interface{}) (string, error) { return "", err } defer tmpFile.Close() - return tmpFile.Name(), runTemplate(templateName, data, tmpFile) + return tmpFile.Name(), RunTemplate(templateName, data, tmpFile) } func TemplateProcessor() *template.Template { @@ -155,7 +155,7 @@ func TemplateProcessor() *template.Template { return template.New("gojira").Funcs(funcs) } -func runTemplate(templateName string, data interface{}, out io.Writer) error { +func RunTemplate(templateName string, data interface{}, out io.Writer) error { templateContent, err := getTemplate(templateName) if err != nil { @@ -194,7 +194,7 @@ func runTemplate(templateName string, data interface{}, out io.Writer) error { return nil } -var allTemplates = map[string]string{ +var AllTemplates = map[string]string{ "component-add": defaultComponentAddTemplate, "debug": defaultDebugTemplate, "fields": defaultDebugTemplate, diff --git a/jiracli/util.go b/jiracli/util.go index a32ec48f..102ffd8c 100644 --- a/jiracli/util.go +++ b/jiracli/util.go @@ -50,7 +50,7 @@ func tmpYml(tmpFilePrefix string) (*os.File, error) { return os.OpenFile(newFileName, os.O_RDWR|os.O_EXCL, 0600) } -func flagValue(ctx *kingpin.ParseContext, name string) string { +func FlagValue(ctx *kingpin.ParseContext, name string) string { for _, elem := range ctx.Elements { if flag, ok := elem.Clause.(*kingpin.FlagClause); ok { if flag.Model().Name == name { diff --git a/jiracli/assign.go b/jiracmd/assign.go similarity index 71% rename from jiracli/assign.go rename to jiracmd/assign.go index c39acb3e..420d01bb 100644 --- a/jiracli/assign.go +++ b/jiracmd/assign.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,38 +6,39 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type AssignOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Assignee string `yaml:"assignee,omitempty" json:"assignee,omitempty"` } -func CmdAssignRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdAssignRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := AssignOptions{} - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Assign user to issue", func() error { return CmdAssign(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdAssignUsage(cmd, &opts) }, } } func CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) cmd.Flag("default", "use default user for assignee").PreAction(func(ctx *kingpin.ParseContext) error { - if flagValue(ctx, "default") == "true" { + if jiracli.FlagValue(ctx, "default") == "true" { opts.Assignee = "-1" } return nil diff --git a/jiracli/block.go b/jiracmd/block.go similarity index 74% rename from jiracli/block.go rename to jiracmd/block.go index 9541cdf0..f7907700 100644 --- a/jiracli/block.go +++ b/jiracmd/block.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,19 +6,20 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type BlockOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"` } -func CmdBlockRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdBlockRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := BlockOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("edit"), }, LinkIssueRequest: jiradata.LinkIssueRequest{ @@ -30,28 +31,28 @@ func CmdBlockRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntr }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Mark issues as blocker", func() error { return CmdBlock(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdBlockUsage(cmd, &opts) }, } } func CmdBlockUsage(cmd *kingpin.CmdClause, opts *BlockOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - EditorUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + 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 { opts.Comment = &jiradata.Comment{ - Body: flagValue(ctx, "comment"), + Body: jiracli.FlagValue(ctx, "comment"), } return nil }).String() diff --git a/jiracli/browse.go b/jiracmd/browse.go similarity index 61% rename from jiracli/browse.go rename to jiracmd/browse.go index d59b6914..7a058956 100644 --- a/jiracli/browse.go +++ b/jiracmd/browse.go @@ -1,35 +1,36 @@ -package jiracli +package jiracmd import ( "fmt" "github.com/coryb/figtree" "github.com/pkg/browser" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type BrowseOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` - Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` } -func CmdBrowseRegistry(fig *figtree.FigTree) *CommandRegistryEntry { +func CmdBrowseRegistry(fig *figtree.FigTree) *jiracli.CommandRegistryEntry { opts := BrowseOptions{} - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Open issue in browser", func() error { return CmdBrowse(&opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdBrowseUsage(cmd, &opts) }, } } func CmdBrowseUsage(cmd *kingpin.CmdClause, opts *BrowseOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } cmd.Arg("ISSUE", "Issue to browse to").Required().StringVar(&opts.Issue) diff --git a/jiracli/comment.go b/jiracmd/comment.go similarity index 66% rename from jiracli/comment.go rename to jiracmd/comment.go index 9061939e..71df297e 100644 --- a/jiracli/comment.go +++ b/jiracmd/comment.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,46 +6,47 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type CommentOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` } -func CmdCommentRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdCommentRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := CommentOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("comment"), }, Overrides: map[string]string{}, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Add comment to issue", func() error { return CmdComment(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdCommentUsage(cmd, &opts) }, } } func CmdCommentUsage(cmd *kingpin.CmdClause, opts *CommentOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - EditorUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + 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 { - opts.Overrides["comment"] = flagValue(ctx, "comment") + opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment") return nil }).String() cmd.Arg("ISSUE", "issue id to update").StringVar(&opts.Issue) @@ -60,7 +61,7 @@ func CmdComment(o *oreo.Client, opts *CommentOptions) error { }{ opts.Overrides, } - err := editLoop(&opts.GlobalOptions, &input, &comment, func() error { + err := jiracli.EditLoop(&opts.GlobalOptions, &input, &comment, func() error { _, err := jira.IssueAddComment(o, opts.Endpoint.Value, opts.Issue, &comment) return err }) diff --git a/jiracli/componentAdd.go b/jiracmd/componentAdd.go similarity index 73% rename from jiracli/componentAdd.go rename to jiracmd/componentAdd.go index f60df334..52268864 100644 --- a/jiracli/componentAdd.go +++ b/jiracmd/componentAdd.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,41 +6,42 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type ComponentAddOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiradata.Component `yaml:",inline" json:",inline" figtree:",inline"` } -func CmdComponentAddRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdComponentAddRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := ComponentAddOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("component-add"), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Add component", func() error { return CmdComponentAdd(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdComponentAddUsage(cmd, &opts) }, } } func CmdComponentAddUsage(cmd *kingpin.CmdClause, opts *ComponentAddOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - EditorUsage(cmd, &opts.GlobalOptions) - TemplateUsage(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("project", "project to create component in").Short('p').StringVar(&opts.Project) cmd.Flag("name", "name of component").Short('n').StringVar(&opts.Name) @@ -55,7 +56,7 @@ func CmdComponentAdd(o *oreo.Client, opts *ComponentAddOptions) error { var err error component := &jiradata.Component{} var resp *jiradata.Component - err = editLoop(&opts.GlobalOptions, &opts.Component, component, func() error { + err = jiracli.EditLoop(&opts.GlobalOptions, &opts.Component, component, func() error { resp, err = jira.CreateComponent(o, opts.Endpoint.Value, component) return err }) diff --git a/jiracli/components.go b/jiracmd/components.go similarity index 68% rename from jiracli/components.go rename to jiracmd/components.go index 2660a1dc..b7098272 100644 --- a/jiracli/components.go +++ b/jiracmd/components.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,39 +6,40 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type ComponentsOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Project string `yaml:"project,omitempty" json:"project,omitempty"` } -func CmdComponentsRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdComponentsRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := ComponentsOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("components"), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Show components for a project", func() error { return CmdComponents(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdComponentsUsage(cmd, &opts) }, } } func CmdComponentsUsage(cmd *kingpin.CmdClause, opts *ComponentsOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - TemplateUsage(cmd, &opts.GlobalOptions) + jiracli.TemplateUsage(cmd, &opts.GlobalOptions) cmd.Flag("project", "project to list components").Short('p').StringVar(&opts.Project) return nil @@ -53,5 +54,5 @@ func CmdComponents(o *oreo.Client, opts *ComponentsOptions) error { if err != nil { return err } - return runTemplate(opts.Template.Value, data, nil) + return jiracli.RunTemplate(opts.Template.Value, data, nil) } diff --git a/jiracli/create.go b/jiracmd/create.go similarity index 84% rename from jiracli/create.go rename to jiracmd/create.go index e065d905..a8ccfb16 100644 --- a/jiracli/create.go +++ b/jiracmd/create.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -7,14 +7,15 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" yaml "gopkg.in/coryb/yaml.v2" ) type CreateOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"` Project string `yaml:"project,omitempty" json:"project,omitempty"` IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"` @@ -22,38 +23,38 @@ type CreateOptions struct { SaveFile string `yaml:"savefile,omitempty" json:"savefile,omitempty"` } -func CmdCreateRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdCreateRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := CreateOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("create"), }, Overrides: map[string]string{}, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Create issue", func() error { return CmdCreate(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdCreateUsage(cmd, &opts) }, } } func CmdCreateUsage(cmd *kingpin.CmdClause, opts *CreateOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - EditorUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + 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("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("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error { - opts.Overrides["comment"] = flagValue(ctx, "comment") + opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment") return nil }).String() cmd.Flag("override", "Set issue property").Short('o').StringMapVar(&opts.Overrides) @@ -87,7 +88,7 @@ func CmdCreate(o *oreo.Client, opts *CreateOptions) error { input.Overrides["user"] = opts.User.Value var issueResp *jiradata.IssueCreateResponse - err = editLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { + err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { issueResp, err = jira.CreateIssue(o, opts.Endpoint.Value, &issueUpdate) return err }) diff --git a/jiracli/createmeta.go b/jiracmd/createmeta.go similarity index 72% rename from jiracli/createmeta.go rename to jiracmd/createmeta.go index 2e102960..ca26b93a 100644 --- a/jiracli/createmeta.go +++ b/jiracmd/createmeta.go @@ -1,42 +1,43 @@ -package jiracli +package jiracmd import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type CreateMetaOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Project string `yaml:"project,omitempty" json:"project,omitempty"` IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"` } -func CmdCreateMetaRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdCreateMetaRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := CreateMetaOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("createmeta"), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "View 'create' metadata", func() error { return CmdCreateMeta(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdCreateMetaUsage(cmd, &opts) }, } } func CmdCreateMetaUsage(cmd *kingpin.CmdClause, opts *CreateMetaOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - TemplateUsage(cmd, &opts.GlobalOptions) + jiracli.TemplateUsage(cmd, &opts.GlobalOptions) 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) return nil @@ -51,5 +52,5 @@ func CmdCreateMeta(o *oreo.Client, opts *CreateMetaOptions) error { if err != nil { return err } - return runTemplate(opts.Template.Value, createMeta, nil) + return jiracli.RunTemplate(opts.Template.Value, createMeta, nil) } diff --git a/jiracli/dup.go b/jiracmd/dup.go similarity index 80% rename from jiracli/dup.go rename to jiracmd/dup.go index fefcd8ec..0a46b2a7 100644 --- a/jiracli/dup.go +++ b/jiracmd/dup.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,21 +6,22 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type DupOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"` Duplicate string `yaml:"duplicate,omitempty" json:"duplicate,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` } -func CmdDupRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdDupRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := DupOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("edit"), }, LinkIssueRequest: jiradata.LinkIssueRequest{ @@ -32,28 +33,28 @@ func CmdDupRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Mark issues as duplicate", func() error { return CmdDup(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdDupUsage(cmd, &opts) }, } } func CmdDupUsage(cmd *kingpin.CmdClause, opts *DupOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - EditorUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + 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 { opts.Comment = &jiradata.Comment{ - Body: flagValue(ctx, "comment"), + Body: jiracli.FlagValue(ctx, "comment"), } return nil }).String() diff --git a/jiracli/edit.go b/jiracmd/edit.go similarity index 78% rename from jiracli/edit.go rename to jiracmd/edit.go index 1ac8eec9..e238f34f 100644 --- a/jiracli/edit.go +++ b/jiracmd/edit.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,50 +6,51 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type EditOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"` jira.SearchOptions `yaml:",inline" json:",inline" figtree:",inline"` Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` } -func CmdEditRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdEditRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := EditOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("edit"), }, Overrides: map[string]string{}, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Edit issue details", func() error { return CmdEdit(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdEditUsage(cmd, &opts) }, } } func CmdEditUsage(cmd *kingpin.CmdClause, opts *EditOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - EditorUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + 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("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 { - opts.Overrides["comment"] = flagValue(ctx, "comment") + opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment") return nil }).String() cmd.Flag("override", "Set issue property").Short('o').StringMapVar(&opts.Overrides) @@ -80,7 +81,7 @@ func CmdEdit(o *oreo.Client, opts *EditOptions) error { Meta: editMeta, Overrides: opts.Overrides, } - err = editLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { + err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { return jira.EditIssue(o, opts.Endpoint.Value, opts.Issue, &issueUpdate) }) if err != nil { @@ -107,7 +108,7 @@ func CmdEdit(o *oreo.Client, opts *EditOptions) error { Issue: issueData, Meta: editMeta, } - err = editLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { + err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { return jira.EditIssue(o, opts.Endpoint.Value, issueData.Key, &issueUpdate) }) if err != nil { diff --git a/jiracli/editmeta.go b/jiracmd/editmeta.go similarity index 65% rename from jiracli/editmeta.go rename to jiracmd/editmeta.go index 93d2381f..554692c8 100644 --- a/jiracli/editmeta.go +++ b/jiracmd/editmeta.go @@ -1,43 +1,44 @@ -package jiracli +package jiracmd import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type EditMetaOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` } -func CmdEditMetaRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdEditMetaRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := EditMetaOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("editmeta"), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "View 'edit' metadata", func() error { return CmdEditMeta(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdEditMetaUsage(cmd, &opts) }, } } func CmdEditMetaUsage(cmd *kingpin.CmdClause, opts *EditMetaOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.TemplateUsage(cmd, &opts.GlobalOptions) cmd.Arg("ISSUE", "edit metadata for issue id").Required().StringVar(&opts.Issue) return nil } @@ -48,7 +49,7 @@ func CmdEditMeta(o *oreo.Client, opts *EditMetaOptions) error { if err != nil { return err } - if err := runTemplate(opts.Template.Value, editMeta, nil); err != nil { + if err := jiracli.RunTemplate(opts.Template.Value, editMeta, nil); err != nil { return err } if opts.Browse.Value { diff --git a/jiracli/exportTemplates.go b/jiracmd/exportTemplates.go similarity index 81% rename from jiracli/exportTemplates.go rename to jiracmd/exportTemplates.go index 4a7ec257..65e21d5d 100644 --- a/jiracli/exportTemplates.go +++ b/jiracmd/exportTemplates.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,7 +6,7 @@ import ( "path" "github.com/coryb/figtree" - + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) @@ -15,18 +15,18 @@ type ExportTemplatesOptions struct { Dir string `yaml:"dir,omitempty" json:"dir,omitempty"` } -func CmdExportTemplatesRegistry(fig *figtree.FigTree) *CommandRegistryEntry { +func CmdExportTemplatesRegistry(fig *figtree.FigTree) *jiracli.CommandRegistryEntry { opts := ExportTemplatesOptions{} - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Export templates for customizations", func() error { return CmdExportTemplates(&opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) if opts.Dir == "" { - opts.Dir = fmt.Sprintf("%s/.jira.d/templates", Homedir()) + opts.Dir = fmt.Sprintf("%s/.jira.d/templates", jiracli.Homedir()) } return CmdExportTemplatesUsage(cmd, &opts) }, @@ -46,7 +46,7 @@ func CmdExportTemplates(opts *ExportTemplatesOptions) error { return err } - for name, template := range allTemplates { + for name, template := range jiracli.AllTemplates { if opts.Template != "" && opts.Template != name { continue } diff --git a/jiracmd/fields.go b/jiracmd/fields.go new file mode 100644 index 00000000..801dc912 --- /dev/null +++ b/jiracmd/fields.go @@ -0,0 +1,36 @@ +package jiracmd + +import ( + "github.com/coryb/figtree" + "github.com/coryb/oreo" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" + kingpin "gopkg.in/alecthomas/kingpin.v2" +) + +func CmdFieldsRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { + opts := jiracli.GlobalOptions{ + Template: figtree.NewStringOption("fields"), + } + return &jiracli.CommandRegistryEntry{ + "Prints all fields, both System and Custom", + func() error { + return CmdFields(o, &opts) + }, + func(cmd *kingpin.CmdClause) error { + jiracli.LoadConfigs(cmd, fig, &opts) + err := jiracli.GlobalUsage(cmd, &opts) + jiracli.TemplateUsage(cmd, &opts) + return err + }, + } +} + +// Fields will send data from /rest/api/2/field API to "fields" template +func CmdFields(o *oreo.Client, opts *jiracli.GlobalOptions) error { + data, err := jira.GetFields(o, opts.Endpoint.Value) + if err != nil { + return err + } + return jiracli.RunTemplate(opts.Template.Value, data, nil) +} diff --git a/jiracli/issuelink.go b/jiracmd/issuelink.go similarity index 78% rename from jiracli/issuelink.go rename to jiracmd/issuelink.go index 8f7af232..ae3807d5 100644 --- a/jiracli/issuelink.go +++ b/jiracmd/issuelink.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,18 +6,19 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type IssueLinkOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"` LinkType string `yaml:"linktype,omitempty" json:"linktype,omitempty"` } -func CmdIssueLinkRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdIssueLinkRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := IssueLinkOptions{ LinkIssueRequest: jiradata.LinkIssueRequest{ Type: &jiradata.IssueLinkType{}, @@ -25,28 +26,28 @@ func CmdIssueLinkRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistry OutwardIssue: &jiradata.IssueRef{}, }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Link two issues", func() error { return CmdIssueLink(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdIssueLinkUsage(cmd, &opts) }, } } func CmdIssueLinkUsage(cmd *kingpin.CmdClause, opts *IssueLinkOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - EditorUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + 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 { opts.Comment = &jiradata.Comment{ - Body: flagValue(ctx, "comment"), + Body: jiracli.FlagValue(ctx, "comment"), } return nil }).String() diff --git a/jiracli/issuelinktypes.go b/jiracmd/issuelinktypes.go similarity index 52% rename from jiracli/issuelinktypes.go rename to jiracmd/issuelinktypes.go index f529a946..3c1abfd6 100644 --- a/jiracli/issuelinktypes.go +++ b/jiracmd/issuelinktypes.go @@ -1,42 +1,43 @@ -package jiracli +package jiracmd import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) -func CmdIssueLinkTypesRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { - opts := GlobalOptions{ +func CmdIssueLinkTypesRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { + opts := jiracli.GlobalOptions{ Template: figtree.NewStringOption("issuelinktypes"), } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Show the issue link types", func() error { return CmdIssueLinkTypes(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdIssueLinkTypesUsage(cmd, &opts) }, } } -func CmdIssueLinkTypesUsage(cmd *kingpin.CmdClause, opts *GlobalOptions) error { - if err := GlobalUsage(cmd, opts); err != nil { +func CmdIssueLinkTypesUsage(cmd *kingpin.CmdClause, opts *jiracli.GlobalOptions) error { + if err := jiracli.GlobalUsage(cmd, opts); err != nil { return err } - TemplateUsage(cmd, opts) + jiracli.TemplateUsage(cmd, opts) return nil } // CmdIssueLinkTypes will get issue link type data and send to "issuelinktypes" template -func CmdIssueLinkTypes(o *oreo.Client, opts *GlobalOptions) error { +func CmdIssueLinkTypes(o *oreo.Client, opts *jiracli.GlobalOptions) error { data, err := jira.GetIssueLinkTypes(o, opts.Endpoint.Value) if err != nil { return err } - return runTemplate(opts.Template.Value, data, nil) + return jiracli.RunTemplate(opts.Template.Value, data, nil) } diff --git a/jiracli/issuetypes.go b/jiracmd/issuetypes.go similarity index 68% rename from jiracli/issuetypes.go rename to jiracmd/issuetypes.go index 80a7f589..14dd7ac7 100644 --- a/jiracli/issuetypes.go +++ b/jiracmd/issuetypes.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,39 +6,40 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type IssueTypesOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Project string `yaml:"project,omitempty" json:"project,omitempty"` } -func CmdIssueTypesRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdIssueTypesRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := IssueTypesOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("issuetypes"), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Show issue types for a project", func() error { return CmdIssueTypes(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdIssueTypesUsage(cmd, &opts) }, } } func CmdIssueTypesUsage(cmd *kingpin.CmdClause, opts *IssueTypesOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - TemplateUsage(cmd, &opts.GlobalOptions) + jiracli.TemplateUsage(cmd, &opts.GlobalOptions) cmd.Flag("project", "project to list issueTypes").Short('p').StringVar(&opts.Project) return nil @@ -53,5 +54,5 @@ func CmdIssueTypes(o *oreo.Client, opts *IssueTypesOptions) error { if err != nil { return err } - return runTemplate(opts.Template.Value, data, nil) + return jiracli.RunTemplate(opts.Template.Value, data, nil) } diff --git a/jiracli/labelsAdd.go b/jiracmd/labelsAdd.go similarity index 78% rename from jiracli/labelsAdd.go rename to jiracmd/labelsAdd.go index 68041ef6..5f51d5a4 100644 --- a/jiracli/labelsAdd.go +++ b/jiracmd/labelsAdd.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,36 +6,37 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type LabelsAddOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"` } -func CmdLabelsAddRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdLabelsAddRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := LabelsAddOptions{} - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Add labels to an issue", func() error { return CmdLabelsAdd(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdLabelsAddUsage(cmd, &opts) }, } } func CmdLabelsAddUsage(cmd *kingpin.CmdClause, opts *LabelsAddOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue) cmd.Arg("LABEL", "label to add to issue").Required().StringsVar(&opts.Labels) return nil diff --git a/jiracli/labelsRemove.go b/jiracmd/labelsRemove.go similarity index 79% rename from jiracli/labelsRemove.go rename to jiracmd/labelsRemove.go index eac1da53..7323240b 100644 --- a/jiracli/labelsRemove.go +++ b/jiracmd/labelsRemove.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,36 +6,37 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type LabelsRemoveOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"` } -func CmdLabelsRemoveRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdLabelsRemoveRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := LabelsRemoveOptions{} - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Remove labels from an issue", func() error { return CmdLabelsRemove(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdLabelsRemoveUsage(cmd, &opts) }, } } func CmdLabelsRemoveUsage(cmd *kingpin.CmdClause, opts *LabelsRemoveOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue) cmd.Arg("LABEL", "label to remove from issue").Required().StringsVar(&opts.Labels) return nil diff --git a/jiracli/labelsSet.go b/jiracmd/labelsSet.go similarity index 78% rename from jiracli/labelsSet.go rename to jiracmd/labelsSet.go index ec2ee90d..cce7b71e 100644 --- a/jiracli/labelsSet.go +++ b/jiracmd/labelsSet.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,36 +6,37 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type LabelsSetOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"` } -func CmdLabelsSetRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdLabelsSetRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := LabelsSetOptions{} - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Set labels on an issue", func() error { return CmdLabelsSet(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdLabelsSetUsage(cmd, &opts) }, } } func CmdLabelsSetUsage(cmd *kingpin.CmdClause, opts *LabelsSetOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue) cmd.Arg("LABEL", "label to set on issue").Required().StringsVar(&opts.Labels) return nil diff --git a/jiracli/list.go b/jiracmd/list.go similarity index 77% rename from jiracli/list.go rename to jiracmd/list.go index b149c436..a2181e85 100644 --- a/jiracli/list.go +++ b/jiracmd/list.go @@ -1,31 +1,32 @@ -package jiracli +package jiracmd import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type ListOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jira.SearchOptions `yaml:",inline" json:",inline" figtree:",inline"` } -func CmdListRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdListRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := ListOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("list"), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Prints list of issues for given search criteria", func() error { return CmdList(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) if opts.MaxResults == 0 { opts.MaxResults = 500 } @@ -41,10 +42,10 @@ func CmdListRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry } func CmdListUsage(cmd *kingpin.CmdClause, opts *ListOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - TemplateUsage(cmd, &opts.GlobalOptions) + jiracli.TemplateUsage(cmd, &opts.GlobalOptions) 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("issuetype", "Issue type to search for").Short('i').StringVar(&opts.IssueType) @@ -64,5 +65,5 @@ func CmdList(o *oreo.Client, opts *ListOptions) error { if err != nil { return err } - return runTemplate(opts.Template.Value, data, nil) + return jiracli.RunTemplate(opts.Template.Value, data, nil) } diff --git a/jiracli/login.go b/jiracmd/login.go similarity index 79% rename from jiracli/login.go rename to jiracmd/login.go index 5fcfa9bf..c4613658 100644 --- a/jiracli/login.go +++ b/jiracmd/login.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -7,20 +7,21 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" "github.com/mgutz/ansi" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) -func CmdLoginRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { - opts := GlobalOptions{} - return &CommandRegistryEntry{ +func CmdLoginRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { + opts := jiracli.GlobalOptions{} + return &jiracli.CommandRegistryEntry{ "Attempt to login into jira server", func() error { return CmdLogin(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) - return GlobalUsage(cmd, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) + return jiracli.GlobalUsage(cmd, &opts) }, } } @@ -44,7 +45,7 @@ func authCallback(req *http.Request, resp *http.Response) (*http.Response, error } // CmdLogin will attempt to login into jira server -func CmdLogin(o *oreo.Client, opts *GlobalOptions) error { +func CmdLogin(o *oreo.Client, opts *jiracli.GlobalOptions) error { ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks().WithPostCallback(authCallback) for { if session, err := jira.GetSession(o, opts.Endpoint.Value); err != nil { diff --git a/jiracli/logout.go b/jiracmd/logout.go similarity index 61% rename from jiracli/logout.go rename to jiracmd/logout.go index fa93151a..ead3bcf5 100644 --- a/jiracli/logout.go +++ b/jiracmd/logout.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,26 +6,27 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" "github.com/mgutz/ansi" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) -func CmdLogoutRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { - opts := GlobalOptions{} - return &CommandRegistryEntry{ +func CmdLogoutRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { + opts := jiracli.GlobalOptions{} + return &jiracli.CommandRegistryEntry{ "Deactivate sesssion with Jira server", func() error { return CmdLogout(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) - return GlobalUsage(cmd, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) + return jiracli.GlobalUsage(cmd, &opts) }, } } // CmdLogout will attempt to terminate an active Jira session -func CmdLogout(o *oreo.Client, opts *GlobalOptions) error { +func CmdLogout(o *oreo.Client, opts *jiracli.GlobalOptions) error { ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks() err := jira.DeleteSession(ua, opts.Endpoint.Value) if err == nil { diff --git a/jiracli/rank.go b/jiracmd/rank.go similarity index 78% rename from jiracli/rank.go rename to jiracmd/rank.go index 4ceb60e9..05ae4dec 100644 --- a/jiracli/rank.go +++ b/jiracmd/rank.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,38 +6,39 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type RankOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` First string `yaml:"first,omitempty" json:"first,omitempty"` Second string `yaml:"second,omitempty" json:"second,omitempty"` Order string `yaml:"order,omitempty" json:"order,omitempty"` } -func CmdRankRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdRankRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := RankOptions{} - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Mark issues as blocker", func() error { return CmdRank(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdRankUsage(cmd, &opts) }, } } func CmdRankUsage(cmd *kingpin.CmdClause, opts *RankOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) 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("SECOND-ISSUE", "second issue").Required().StringVar(&opts.Second) diff --git a/jiracli/request.go b/jiracmd/request.go similarity index 70% rename from jiracli/request.go rename to jiracmd/request.go index 4c040817..5c6a7ffa 100644 --- a/jiracli/request.go +++ b/jiracmd/request.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "encoding/json" @@ -10,30 +10,31 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type RequestOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` - Method string `yaml:"method,omitempty" json:"method,omitempty"` - URI string `yaml:"uri,omitempty" json:"uri,omitempty"` - Data string `yaml:"data,omitempty" json:"data,omitempty"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + Method string `yaml:"method,omitempty" json:"method,omitempty"` + URI string `yaml:"uri,omitempty" json:"uri,omitempty"` + Data string `yaml:"data,omitempty" json:"data,omitempty"` } -func CmdRequestRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdRequestRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := RequestOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("request"), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Open issue in requestr", func() error { return CmdRequest(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) if opts.Method == "" { opts.Method = "GET" } @@ -43,7 +44,7 @@ func CmdRequestRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEn } func CmdRequestUsage(cmd *kingpin.CmdClause, opts *RequestOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + 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") @@ -89,5 +90,5 @@ func CmdRequest(o *oreo.Client, opts *RequestOptions) error { return fmt.Errorf("JSON Parse Error: %s from %q", err, content) } - return runTemplate(opts.Template.Value, &data, nil) + return jiracli.RunTemplate(opts.Template.Value, &data, nil) } diff --git a/jiracli/subtask.go b/jiracmd/subtask.go similarity index 80% rename from jiracli/subtask.go rename to jiracmd/subtask.go index 7802efb3..1176ffee 100644 --- a/jiracli/subtask.go +++ b/jiracmd/subtask.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,13 +6,14 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type SubtaskOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiradata.IssueUpdate `yaml:",inline" json:",inline" figtree:",inline"` Project string `yaml:"project,omitempty" json:"project,omitempty"` IssueType string `yaml:"issuetype,omitempty" json:"issuetype,omitempty"` @@ -20,21 +21,21 @@ type SubtaskOptions struct { Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` } -func CmdSubtaskRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdSubtaskRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := SubtaskOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("subtask"), }, Overrides: map[string]string{}, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Subtask issue", func() error { return CmdSubtask(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) if opts.IssueType == "" { opts.IssueType = "Sub-task" } @@ -44,16 +45,16 @@ func CmdSubtaskRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEn } func CmdSubtaskUsage(cmd *kingpin.CmdClause, opts *SubtaskOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - EditorUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + 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("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 { - opts.Overrides["comment"] = flagValue(ctx, "comment") + opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment") return nil }).String() cmd.Flag("override", "Set issue property").Short('o').StringMapVar(&opts.Overrides) @@ -101,7 +102,7 @@ func CmdSubtask(o *oreo.Client, opts *SubtaskOptions) error { input.Overrides["user"] = opts.User.Value var issueResp *jiradata.IssueCreateResponse - err = editLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { + err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { issueResp, err = jira.CreateIssue(o, opts.Endpoint.Value, &issueUpdate) return err }) diff --git a/jiracli/take.go b/jiracmd/take.go similarity index 59% rename from jiracli/take.go rename to jiracmd/take.go index a82ea1e3..72eb4520 100644 --- a/jiracli/take.go +++ b/jiracmd/take.go @@ -1,32 +1,33 @@ -package jiracli +package jiracmd import ( "github.com/coryb/figtree" "github.com/coryb/oreo" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) -func CmdTakeRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdTakeRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := AssignOptions{} - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Assign issue to yourself", func() error { opts.Assignee = opts.User.Value return CmdAssign(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdAssignUsage(cmd, &opts) }, } } func CmdTakeUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) cmd.Arg("ISSUE", "issue to assign").Required().StringVar(&opts.Issue) return nil } diff --git a/jiracli/transition.go b/jiracmd/transition.go similarity index 79% rename from jiracli/transition.go rename to jiracmd/transition.go index 079edce7..2828beec 100644 --- a/jiracli/transition.go +++ b/jiracmd/transition.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -7,22 +7,23 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type TransitionOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"` Transition string `yaml:"transition,omitempty" json:"transition,omitempty"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Resolution string `yaml:"resolution,omitempty" json:"resolution,omitempty"` } -func CmdTransitionRegistry(fig *figtree.FigTree, o *oreo.Client, transition string) *CommandRegistryEntry { +func CmdTransitionRegistry(fig *figtree.FigTree, o *oreo.Client, transition string) *jiracli.CommandRegistryEntry { opts := TransitionOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("transition"), }, Overrides: map[string]string{}, @@ -34,13 +35,13 @@ func CmdTransitionRegistry(fig *figtree.FigTree, o *oreo.Client, transition stri opts.SkipEditing = figtree.NewBoolOption(true) } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ help, func() error { return CmdTransition(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) if opts.Transition == "" { opts.Transition = transition } @@ -50,14 +51,14 @@ func CmdTransitionRegistry(fig *figtree.FigTree, o *oreo.Client, transition stri } func CmdTransitionUsage(cmd *kingpin.CmdClause, opts *TransitionOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.TemplateUsage(cmd, &opts.GlobalOptions) 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 { - opts.Overrides["comment"] = flagValue(ctx, "comment") + opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment") return nil }).String() cmd.Flag("override", "Set issue property").Short('o').StringMapVar(&opts.Overrides) @@ -72,12 +73,12 @@ func CmdTransitionUsage(cmd *kingpin.CmdClause, opts *TransitionOptions) error { func CmdTransition(o *oreo.Client, opts *TransitionOptions) error { issueData, err := jira.GetIssue(o, opts.Endpoint.Value, opts.Issue, nil) if err != nil { - return cliError(err) + return jiracli.CliError(err) } meta, err := jira.GetIssueTransitions(o, opts.Endpoint.Value, opts.Issue) if err != nil { - return cliError(err) + return jiracli.CliError(err) } transMeta := meta.Transitions.Find(opts.Transition) @@ -89,10 +90,10 @@ func CmdTransition(o *oreo.Client, opts *TransitionOptions) error { if status, ok := issueData.Fields["status"].(map[string]interface{}); ok { if name, ok := status["name"].(string); ok { - return cliError(fmt.Errorf("Invalid Transition %q from %q, Available: %s", opts.Transition, name, strings.Join(possible, ", "))) + return jiracli.CliError(fmt.Errorf("Invalid Transition %q from %q, Available: %s", opts.Transition, name, strings.Join(possible, ", "))) } } - return cliError(fmt.Errorf("No valid transition found matching %s", opts.Transition)) + return jiracli.CliError(fmt.Errorf("No valid transition found matching %s", opts.Transition)) } // need to default the Resolution, usually Fixed works but sometime need Done @@ -127,11 +128,11 @@ func CmdTransition(o *oreo.Client, opts *TransitionOptions) error { Transition: transMeta, Overrides: opts.Overrides, } - err = editLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { + err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error { return jira.TransitionIssue(o, opts.Endpoint.Value, opts.Issue, &issueUpdate) }) if err != nil { - return cliError(err) + return jiracli.CliError(err) } fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, opts.Endpoint.Value, issueData.Key) diff --git a/jiracli/transitions.go b/jiracmd/transitions.go similarity index 65% rename from jiracli/transitions.go rename to jiracmd/transitions.go index 3bb9946d..09572e52 100644 --- a/jiracli/transitions.go +++ b/jiracmd/transitions.go @@ -1,42 +1,43 @@ -package jiracli +package jiracmd import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type TransitionsOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` } -func CmdTransitionsRegistry(fig *figtree.FigTree, o *oreo.Client, defaultTemplate string) *CommandRegistryEntry { +func CmdTransitionsRegistry(fig *figtree.FigTree, o *oreo.Client, defaultTemplate string) *jiracli.CommandRegistryEntry { opts := TransitionsOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption(defaultTemplate), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "List valid issue transitions", func() error { return CmdTransitions(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdTransitionsUsage(cmd, &opts) }, } } func CmdTransitionsUsage(cmd *kingpin.CmdClause, opts *TransitionsOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.TemplateUsage(cmd, &opts.GlobalOptions) cmd.Arg("ISSUE", "issue to list valid transitions").Required().StringVar(&opts.Issue) return nil } @@ -47,7 +48,7 @@ func CmdTransitions(o *oreo.Client, opts *TransitionsOptions) error { if err != nil { return err } - if err := runTemplate(opts.Template.Value, editMeta, nil); err != nil { + if err := jiracli.RunTemplate(opts.Template.Value, editMeta, nil); err != nil { return err } if opts.Browse.Value { diff --git a/jiracli/unassign.go b/jiracmd/unassign.go similarity index 64% rename from jiracli/unassign.go rename to jiracmd/unassign.go index 49d4ac80..1c406454 100644 --- a/jiracli/unassign.go +++ b/jiracmd/unassign.go @@ -1,31 +1,32 @@ -package jiracli +package jiracmd import ( "github.com/coryb/figtree" "github.com/coryb/oreo" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) -func CmdUnassignRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdUnassignRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := AssignOptions{} - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Unassign an issue", func() error { return CmdAssign(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdAssignUsage(cmd, &opts) }, } } func CmdUnassignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) cmd.Arg("ISSUE", "issue to unassign").Required().StringVar(&opts.Issue) return nil } diff --git a/jiracli/unexportTemplates.go b/jiracmd/unexportTemplates.go similarity index 76% rename from jiracli/unexportTemplates.go rename to jiracmd/unexportTemplates.go index ab8ccfc4..818cecf3 100644 --- a/jiracli/unexportTemplates.go +++ b/jiracmd/unexportTemplates.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "bytes" @@ -8,22 +8,22 @@ import ( "path" "github.com/coryb/figtree" - + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) -func CmdUnexportTemplatesRegistry(fig *figtree.FigTree) *CommandRegistryEntry { +func CmdUnexportTemplatesRegistry(fig *figtree.FigTree) *jiracli.CommandRegistryEntry { opts := ExportTemplatesOptions{} - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Remove unmodified exported templates", func() error { return CmdUnexportTemplates(&opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) if opts.Dir != "" { - opts.Dir = fmt.Sprintf("%s/.jira.d/templates", Homedir()) + opts.Dir = fmt.Sprintf("%s/.jira.d/templates", jiracli.Homedir()) } return CmdExportTemplatesUsage(cmd, &opts) @@ -33,7 +33,7 @@ func CmdUnexportTemplatesRegistry(fig *figtree.FigTree) *CommandRegistryEntry { // CmdUnexportTemplates will remove unmodified templates from export directory func CmdUnexportTemplates(opts *ExportTemplatesOptions) error { - for name, template := range allTemplates { + for name, template := range jiracli.AllTemplates { if opts.Template != "" && opts.Template != name { continue } diff --git a/jiracli/view.go b/jiracmd/view.go similarity index 66% rename from jiracli/view.go rename to jiracmd/view.go index dddfb866..d699f354 100644 --- a/jiracli/view.go +++ b/jiracmd/view.go @@ -1,43 +1,44 @@ -package jiracli +package jiracmd import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type ViewOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jira.IssueOptions `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` } -func CmdViewRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdViewRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := ViewOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("view"), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Prints issue details", func() error { return CmdView(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdViewUsage(cmd, &opts) }, } } func CmdViewUsage(cmd *kingpin.CmdClause, opts *ViewOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.TemplateUsage(cmd, &opts.GlobalOptions) 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("property", "property to return for issue").StringsVar(&opts.Properties) @@ -51,7 +52,7 @@ func CmdView(o *oreo.Client, opts *ViewOptions) error { if err != nil { return err } - if err := runTemplate(opts.Template.Value, data, nil); err != nil { + if err := jiracli.RunTemplate(opts.Template.Value, data, nil); err != nil { return err } if opts.Browse.Value { diff --git a/jiracli/vote.go b/jiracmd/vote.go similarity index 72% rename from jiracli/vote.go rename to jiracmd/vote.go index 9f17d52a..11008434 100644 --- a/jiracli/vote.go +++ b/jiracmd/vote.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,7 +6,8 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) @@ -18,34 +19,34 @@ const ( ) type VoteOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Action VoteAction `yaml:"-" json:"-"` } -func CmdVoteRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdVoteRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := VoteOptions{ - GlobalOptions: GlobalOptions{}, + GlobalOptions: jiracli.GlobalOptions{}, Action: VoteUP, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Vote up/down an issue", func() error { return CmdVote(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdVoteUsage(cmd, &opts) }, } } func CmdVoteUsage(cmd *kingpin.CmdClause, opts *VoteOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) cmd.Flag("down", "downvote the issue").Short('d').PreAction(func(ctx *kingpin.ParseContext) error { opts.Action = VoteDown return nil diff --git a/jiracli/watch.go b/jiracmd/watch.go similarity index 77% rename from jiracli/watch.go rename to jiracmd/watch.go index 43695cd1..4525b38e 100644 --- a/jiracli/watch.go +++ b/jiracmd/watch.go @@ -1,4 +1,4 @@ -package jiracli +package jiracmd import ( "fmt" @@ -6,7 +6,8 @@ import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) @@ -18,35 +19,35 @@ const ( ) type WatchOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` Watcher string `yaml:"watcher,omitempty" json:"watcher,omitempty"` Action WatchAction `yaml:"-" json:"-"` } -func CmdWatchRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdWatchRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := WatchOptions{ - GlobalOptions: GlobalOptions{}, + GlobalOptions: jiracli.GlobalOptions{}, Action: WatcherAdd, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Add/Remove watcher to issue", func() error { return CmdWatch(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdWatchUsage(cmd, &opts) }, } } func CmdWatchUsage(cmd *kingpin.CmdClause, opts *WatchOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) cmd.Flag("remove", "remove watcher from issue").Short('r').PreAction(func(ctx *kingpin.ParseContext) error { opts.Action = WatcherRemove return nil diff --git a/jiracli/worklogAdd.go b/jiracmd/worklogAdd.go similarity index 71% rename from jiracli/worklogAdd.go rename to jiracmd/worklogAdd.go index ba211cc9..f8a67c4e 100644 --- a/jiracli/worklogAdd.go +++ b/jiracmd/worklogAdd.go @@ -1,44 +1,45 @@ -package jiracli +package jiracmd import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "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/jiradata" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type WorklogAddOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` jiradata.Worklog `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` } -func CmdWorklogAddRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdWorklogAddRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := WorklogAddOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("worklog"), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Add a worklog to an issue", func() error { return CmdWorklogAdd(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdWorklogAddUsage(cmd, &opts) }, } } func CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - EditorUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + 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("comment", "Comment message for worklog").Short('m').StringVar(&opts.Comment) cmd.Flag("time-spent", "Time spent working on issue").Short('T').StringVar(&opts.TimeSpent) @@ -50,7 +51,7 @@ func CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOptions) error { // It will spawn the editor (unless --noedit isused) and post edited YAML // content as JSON to the worklog endpoint func CmdWorklogAdd(o *oreo.Client, opts *WorklogAddOptions) error { - err := editLoop(&opts.GlobalOptions, &opts.Worklog, &opts.Worklog, func() error { + err := jiracli.EditLoop(&opts.GlobalOptions, &opts.Worklog, &opts.Worklog, func() error { _, err := jira.AddIssueWorklog(o, opts.Endpoint.Value, opts.Issue, opts) return err }) diff --git a/jiracli/worklogList.go b/jiracmd/worklogList.go similarity index 66% rename from jiracli/worklogList.go rename to jiracmd/worklogList.go index 3e9a25e9..c53c15d6 100644 --- a/jiracli/worklogList.go +++ b/jiracmd/worklogList.go @@ -1,41 +1,42 @@ -package jiracli +package jiracmd import ( "github.com/coryb/figtree" "github.com/coryb/oreo" - jira "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1" + "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" kingpin "gopkg.in/alecthomas/kingpin.v2" ) type WorklogListOptions struct { - GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` + jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"` Issue string `yaml:"issue,omitempty" json:"issue,omitempty"` } -func CmdWorklogListRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry { +func CmdWorklogListRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry { opts := WorklogListOptions{ - GlobalOptions: GlobalOptions{ + GlobalOptions: jiracli.GlobalOptions{ Template: figtree.NewStringOption("worklogs"), }, } - return &CommandRegistryEntry{ + return &jiracli.CommandRegistryEntry{ "Prints the worklog data for given issue", func() error { return CmdWorklogList(o, &opts) }, func(cmd *kingpin.CmdClause) error { - LoadConfigs(cmd, fig, &opts) + jiracli.LoadConfigs(cmd, fig, &opts) return CmdWorklogListUsage(cmd, &opts) }, } } func CmdWorklogListUsage(cmd *kingpin.CmdClause, opts *WorklogListOptions) error { - if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil { + if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { return err } - BrowseUsage(cmd, &opts.GlobalOptions) - TemplateUsage(cmd, &opts.GlobalOptions) + jiracli.BrowseUsage(cmd, &opts.GlobalOptions) + jiracli.TemplateUsage(cmd, &opts.GlobalOptions) cmd.Arg("ISSUE", "issue id to fetch worklogs").Required().StringVar(&opts.Issue) return nil } @@ -46,7 +47,7 @@ func CmdWorklogList(o *oreo.Client, opts *WorklogListOptions) error { if err != nil { return err } - if err := runTemplate(opts.Template.Value, data, nil); err != nil { + if err := jiracli.RunTemplate(opts.Template.Value, data, nil); err != nil { return err } if opts.Browse.Value {