mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-07 13:33:32 +02:00
refactor trivial objects in favor of arguments to static functions
This commit is contained in:
+11
-9
@@ -3,31 +3,33 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/pkg/browser"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type BrowseOptions struct {
|
||||
GlobalOptions
|
||||
Issue string
|
||||
GlobalOptions `yaml:",inline" figtree:",inline"`
|
||||
Issue string
|
||||
}
|
||||
|
||||
func (jc *JiraCli) CmdBrowseRegistry() *CommandRegistryEntry {
|
||||
func CmdBrowseRegistry(fig *figtree.FigTree) *CommandRegistryEntry {
|
||||
opts := BrowseOptions{}
|
||||
|
||||
return &CommandRegistryEntry{
|
||||
"Open issue in browser",
|
||||
func() error {
|
||||
return jc.CmdBrowse(&opts)
|
||||
return CmdBrowse(&opts)
|
||||
},
|
||||
func(cmd *kingpin.CmdClause) error {
|
||||
return jc.CmdBrowseUsage(cmd, &opts)
|
||||
LoadConfigs(cmd, fig, &opts)
|
||||
return CmdBrowseUsage(cmd, &opts)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (jc *JiraCli) CmdBrowseUsage(cmd *kingpin.CmdClause, opts *BrowseOptions) error {
|
||||
if err := jc.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
|
||||
func CmdBrowseUsage(cmd *kingpin.CmdClause, opts *BrowseOptions) error {
|
||||
if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
cmd.Arg("ISSUE", "Issue to browse to").Required().StringVar(&opts.Issue)
|
||||
@@ -36,6 +38,6 @@ func (jc *JiraCli) CmdBrowseUsage(cmd *kingpin.CmdClause, opts *BrowseOptions) e
|
||||
}
|
||||
|
||||
// CmdBrowse open the default system browser to the provided issue
|
||||
func (jc *JiraCli) CmdBrowse(opts *BrowseOptions) error {
|
||||
return browser.OpenURL(fmt.Sprintf("%s/browse/%s", jc.Endpoint, opts.Issue))
|
||||
func CmdBrowse(opts *BrowseOptions) error {
|
||||
return browser.OpenURL(fmt.Sprintf("%s/browse/%s", opts.Endpoint.Value, opts.Issue))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user