mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-01 02:38:28 +02:00
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package jiracli
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/coryb/figtree"
|
|
"github.com/pkg/browser"
|
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
|
)
|
|
|
|
type BrowseOptions struct {
|
|
GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
|
|
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
|
|
}
|
|
|
|
func CmdBrowseRegistry(fig *figtree.FigTree) *CommandRegistryEntry {
|
|
opts := BrowseOptions{}
|
|
|
|
return &CommandRegistryEntry{
|
|
"Open issue in browser",
|
|
func() error {
|
|
return CmdBrowse(&opts)
|
|
},
|
|
func(cmd *kingpin.CmdClause) error {
|
|
LoadConfigs(cmd, fig, &opts)
|
|
return CmdBrowseUsage(cmd, &opts)
|
|
},
|
|
}
|
|
}
|
|
|
|
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)
|
|
|
|
return nil
|
|
}
|
|
|
|
// CmdBrowse open the default system browser to the provided issue
|
|
func CmdBrowse(opts *BrowseOptions) error {
|
|
return browser.OpenURL(fmt.Sprintf("%s/browse/%s", opts.Endpoint.Value, opts.Issue))
|
|
}
|