mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-19 04:33:28 +02:00
refactor for GlobalOptions and CommonOptions
This commit is contained in:
+23
-26
@@ -13,17 +13,17 @@ import (
|
||||
)
|
||||
|
||||
type SubtaskOptions struct {
|
||||
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"`
|
||||
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
|
||||
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
|
||||
jiracli.CommonOptions `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"`
|
||||
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,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{
|
||||
GlobalOptions: jiracli.GlobalOptions{
|
||||
CommonOptions: jiracli.CommonOptions{
|
||||
Template: figtree.NewStringOption("subtask"),
|
||||
},
|
||||
Overrides: map[string]string{},
|
||||
@@ -31,26 +31,23 @@ func CmdSubtaskRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRe
|
||||
|
||||
return &jiracli.CommandRegistryEntry{
|
||||
"Subtask issue",
|
||||
func() error {
|
||||
return CmdSubtask(o, &opts)
|
||||
},
|
||||
func(cmd *kingpin.CmdClause) error {
|
||||
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
|
||||
jiracli.LoadConfigs(cmd, fig, &opts)
|
||||
if opts.IssueType == "" {
|
||||
opts.IssueType = "Sub-task"
|
||||
}
|
||||
return CmdSubtaskUsage(cmd, &opts)
|
||||
},
|
||||
func(globals *jiracli.GlobalOptions) error {
|
||||
return CmdSubtask(o, globals, &opts)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func CmdSubtaskUsage(cmd *kingpin.CmdClause, opts *SubtaskOptions) error {
|
||||
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
|
||||
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
|
||||
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
|
||||
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
|
||||
jiracli.EditorUsage(cmd, &opts.CommonOptions)
|
||||
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
|
||||
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 {
|
||||
@@ -64,14 +61,14 @@ func CmdSubtaskUsage(cmd *kingpin.CmdClause, opts *SubtaskOptions) error {
|
||||
|
||||
// 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.
|
||||
func CmdSubtask(o *oreo.Client, opts *SubtaskOptions) error {
|
||||
func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOptions) error {
|
||||
type templateInput struct {
|
||||
Meta *jiradata.IssueType `yaml:"meta" json:"meta"`
|
||||
Overrides map[string]string `yaml:"overrides" json:"overrides"`
|
||||
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 {
|
||||
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")
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -99,21 +96,21 @@ func CmdSubtask(o *oreo.Client, opts *SubtaskOptions) error {
|
||||
}
|
||||
input.Overrides["project"] = opts.Project
|
||||
input.Overrides["issuetype"] = opts.IssueType
|
||||
input.Overrides["user"] = opts.User.Value
|
||||
input.Overrides["user"] = globals.User.Value
|
||||
|
||||
var issueResp *jiradata.IssueCreateResponse
|
||||
err = jiracli.EditLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error {
|
||||
issueResp, err = jira.CreateIssue(o, opts.Endpoint.Value, &issueUpdate)
|
||||
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
|
||||
issueResp, err = jira.CreateIssue(o, globals.Endpoint.Value, &issueUpdate)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
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 {
|
||||
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, issueResp.Key})
|
||||
return CmdBrowse(globals, issueResp.Key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user