-
Notifications
You must be signed in to change notification settings - Fork 323
/
view.go
60 lines (54 loc) · 1.85 KB
/
view.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package jiracmd
import (
"github.com/coryb/figtree"
"github.com/coryb/oreo"
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
type ViewOptions struct {
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
jira.IssueOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}
func CmdViewRegistry() *jiracli.CommandRegistryEntry {
opts := ViewOptions{
CommonOptions: jiracli.CommonOptions{
Template: figtree.NewStringOption("view"),
},
}
return &jiracli.CommandRegistryEntry{
"Prints issue details",
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdViewUsage(cmd, &opts)
},
func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
return CmdView(o, globals, &opts)
},
}
}
func CmdViewUsage(cmd *kingpin.CmdClause, opts *ViewOptions) error {
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
jiracli.GJsonQueryUsage(cmd, &opts.CommonOptions)
cmd.Flag("expand", "field to expand for the issue").StringsVar(&opts.Expand)
cmd.Flag("field", "field to return for the issue").StringsVar(&opts.Fields)
cmd.Flag("property", "property to return for issue").StringsVar(&opts.Properties)
cmd.Arg("ISSUE", "issue id to view").Required().StringVar(&opts.Issue)
return nil
}
// View will get issue data and send to "view" template
func CmdView(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ViewOptions) error {
data, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, opts)
if err != nil {
return err
}
if err := opts.PrintTemplate(data); err != nil {
return err
}
if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue)
}
return nil
}