mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-04 20:19:11 +02:00
refactor trivial objects in favor of arguments to static functions
This commit is contained in:
+18
-15
@@ -2,17 +2,19 @@ package jiracli
|
||||
|
||||
import (
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type WorklogAddOptions struct {
|
||||
GlobalOptions
|
||||
jiradata.Worklog
|
||||
Issue string
|
||||
GlobalOptions `yaml:",inline" figtree:",inline"`
|
||||
jiradata.Worklog `yaml:",inline" figtree:",inline"`
|
||||
Issue string
|
||||
}
|
||||
|
||||
func (jc *JiraCli) CmdWorklogAddRegistry() *CommandRegistryEntry {
|
||||
func CmdWorklogAddRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry {
|
||||
opts := WorklogAddOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: figtree.NewStringOption("worklog"),
|
||||
@@ -21,21 +23,22 @@ func (jc *JiraCli) CmdWorklogAddRegistry() *CommandRegistryEntry {
|
||||
return &CommandRegistryEntry{
|
||||
"Add a worklog to an issue",
|
||||
func() error {
|
||||
return jc.CmdWorklogAdd(&opts)
|
||||
return CmdWorklogAdd(o, &opts)
|
||||
},
|
||||
func(cmd *kingpin.CmdClause) error {
|
||||
return jc.CmdWorklogAddUsage(cmd, &opts)
|
||||
LoadConfigs(cmd, fig, &opts)
|
||||
return CmdWorklogAddUsage(cmd, &opts)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (jc *JiraCli) CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOptions) error {
|
||||
if err := jc.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
|
||||
func CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOptions) error {
|
||||
if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
jc.BrowseUsage(cmd, &opts.GlobalOptions)
|
||||
jc.EditorUsage(cmd, &opts.GlobalOptions)
|
||||
jc.TemplateUsage(cmd, &opts.GlobalOptions)
|
||||
BrowseUsage(cmd, &opts.GlobalOptions)
|
||||
EditorUsage(cmd, &opts.GlobalOptions)
|
||||
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)
|
||||
@@ -46,16 +49,16 @@ func (jc *JiraCli) CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOp
|
||||
// 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
|
||||
// content as JSON to the worklog endpoint
|
||||
func (jc *JiraCli) CmdWorklogAdd(opts *WorklogAddOptions) error {
|
||||
err := jc.editLoop(&opts.GlobalOptions, &opts.Worklog, &opts.Worklog, func() error {
|
||||
_, err := jc.AddIssueWorklog(opts.Issue, opts)
|
||||
func CmdWorklogAdd(o *oreo.Client, opts *WorklogAddOptions) error {
|
||||
err := editLoop(&opts.GlobalOptions, &opts.Worklog, &opts.Worklog, func() error {
|
||||
_, err := jira.AddIssueWorklog(o, opts.Endpoint.Value, opts.Issue, opts)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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