mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-13 16:13:34 +02:00
refactor trivial objects in favor of arguments to static functions
This commit is contained in:
+18
-13
@@ -3,34 +3,39 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
|
||||
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type AssignOptions struct {
|
||||
GlobalOptions
|
||||
Issue string
|
||||
Assignee string
|
||||
GlobalOptions `yaml:",inline" figtree:",inline"`
|
||||
Issue string
|
||||
Assignee string
|
||||
}
|
||||
|
||||
func (jc *JiraCli) CmdAssignRegistry() *CommandRegistryEntry {
|
||||
func CmdAssignRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry {
|
||||
opts := AssignOptions{}
|
||||
|
||||
return &CommandRegistryEntry{
|
||||
"Assign user to issue",
|
||||
func() error {
|
||||
return jc.CmdAssign(&opts)
|
||||
return CmdAssign(o, &opts)
|
||||
},
|
||||
func(cmd *kingpin.CmdClause) error {
|
||||
return jc.CmdAssignUsage(cmd, &opts)
|
||||
LoadConfigs(cmd, fig, &opts)
|
||||
return CmdAssignUsage(cmd, &opts)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (jc *JiraCli) CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
|
||||
if err := jc.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
|
||||
func CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
|
||||
if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
jc.BrowseUsage(cmd, &opts.GlobalOptions)
|
||||
BrowseUsage(cmd, &opts.GlobalOptions)
|
||||
cmd.Flag("default", "use default user for assignee").PreAction(func(ctx *kingpin.ParseContext) error {
|
||||
if flagValue(ctx, "default") == "true" {
|
||||
opts.Assignee = "-1"
|
||||
@@ -43,16 +48,16 @@ func (jc *JiraCli) CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) e
|
||||
}
|
||||
|
||||
// CmdAssign will assign an issue to a user
|
||||
func (jc *JiraCli) CmdAssign(opts *AssignOptions) error {
|
||||
err := jc.IssueAssign(opts.Issue, opts.Assignee)
|
||||
func CmdAssign(o *oreo.Client, opts *AssignOptions) error {
|
||||
err := jira.IssueAssign(o, opts.Endpoint.Value, opts.Issue, opts.Assignee)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue)
|
||||
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user