refactor trivial objects in favor of arguments to static functions

This commit is contained in:
Cory Bennett
2017-08-27 00:47:11 -07:00
parent 5716a7cb59
commit 1f345cedee
49 changed files with 840 additions and 629 deletions
+11 -9
View File
@@ -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))
}