mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-05 20:48:28 +02:00
refactor for GlobalOptions and CommonOptions
This commit is contained in:
+17
-20
@@ -13,14 +13,14 @@ import (
|
||||
)
|
||||
|
||||
type CommentOptions struct {
|
||||
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"`
|
||||
jiracli.CommonOptions `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) *jiracli.CommandRegistryEntry {
|
||||
func CmdCommentRegistry(o *oreo.Client) *jiracli.CommandRegistryEntry {
|
||||
opts := CommentOptions{
|
||||
GlobalOptions: jiracli.GlobalOptions{
|
||||
CommonOptions: jiracli.CommonOptions{
|
||||
Template: figtree.NewStringOption("comment"),
|
||||
},
|
||||
Overrides: map[string]string{},
|
||||
@@ -28,23 +28,20 @@ func CmdCommentRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRe
|
||||
|
||||
return &jiracli.CommandRegistryEntry{
|
||||
"Add comment to issue",
|
||||
func() error {
|
||||
return CmdComment(o, &opts)
|
||||
},
|
||||
func(cmd *kingpin.CmdClause) error {
|
||||
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
|
||||
jiracli.LoadConfigs(cmd, fig, &opts)
|
||||
return CmdCommentUsage(cmd, &opts)
|
||||
},
|
||||
func(globals *jiracli.GlobalOptions) error {
|
||||
return CmdComment(o, globals, &opts)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func CmdCommentUsage(cmd *kingpin.CmdClause, opts *CommentOptions) 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("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
|
||||
opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment")
|
||||
return nil
|
||||
@@ -54,25 +51,25 @@ func CmdCommentUsage(cmd *kingpin.CmdClause, opts *CommentOptions) error {
|
||||
}
|
||||
|
||||
// CmdComment will update issue with comment
|
||||
func CmdComment(o *oreo.Client, opts *CommentOptions) error {
|
||||
func CmdComment(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CommentOptions) error {
|
||||
comment := jiradata.Comment{}
|
||||
input := struct {
|
||||
Overrides map[string]string
|
||||
}{
|
||||
opts.Overrides,
|
||||
}
|
||||
err := jiracli.EditLoop(&opts.GlobalOptions, &input, &comment, func() error {
|
||||
_, err := jira.IssueAddComment(o, opts.Endpoint.Value, opts.Issue, &comment)
|
||||
err := jiracli.EditLoop(&opts.CommonOptions, &input, &comment, func() error {
|
||||
_, err := jira.IssueAddComment(o, globals.Endpoint.Value, opts.Issue, &comment)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, opts.Endpoint.Value, opts.Issue)
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
|
||||
|
||||
if opts.Browse.Value {
|
||||
return CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
return CmdBrowse(globals, opts.Issue)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user