|
| 1 | +package jiracmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/coryb/figtree" |
| 5 | + "github.com/coryb/oreo" |
| 6 | + "github.com/go-jira/jira" |
| 7 | + "github.com/go-jira/jira/jiracli" |
| 8 | + kingpin "gopkg.in/alecthomas/kingpin.v2" |
| 9 | +) |
| 10 | + |
| 11 | +type ReleasesOptions struct { |
| 12 | + jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"` |
| 13 | + Project string `yaml:"project,omitempty" json:"project,omitempty"` |
| 14 | + Status []string |
| 15 | + Query string |
| 16 | + OrderBy string |
| 17 | +} |
| 18 | + |
| 19 | +func CmdReleasesRegistry() *jiracli.CommandRegistryEntry { |
| 20 | + opts := ReleasesOptions{ |
| 21 | + CommonOptions: jiracli.CommonOptions{ |
| 22 | + Template: figtree.NewStringOption("releases"), |
| 23 | + }, |
| 24 | + } |
| 25 | + |
| 26 | + return &jiracli.CommandRegistryEntry{ |
| 27 | + Help: "List project releases", |
| 28 | + UsageFunc: func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error { |
| 29 | + jiracli.LoadConfigs(cmd, fig, &opts) |
| 30 | + return CmdReleasesUsage(cmd, &opts) |
| 31 | + }, |
| 32 | + ExecuteFunc: func(o *oreo.Client, globals *jiracli.GlobalOptions) error { |
| 33 | + return CmdReleases(o, globals, &opts) |
| 34 | + }, |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +func CmdReleasesUsage(cmd *kingpin.CmdClause, opts *ReleasesOptions) error { |
| 39 | + jiracli.TemplateUsage(cmd, &opts.CommonOptions) |
| 40 | + jiracli.GJsonQueryUsage(cmd, &opts.CommonOptions) |
| 41 | + cmd.Flag("query", "filter the results using a literal string").Short('q').StringVar(&opts.Query) |
| 42 | + cmd.Flag("status", "list of status values used to filter the results by version status").Short('s').StringsVar(&opts.Status) |
| 43 | + cmd.Flag("order", "order the results by a field: description, name, releaseDate, sequence, startDate").StringVar(&opts.OrderBy) |
| 44 | + cmd.Arg("PROJECT", "project id or key").Required().StringVar(&opts.Project) |
| 45 | + return nil |
| 46 | +} |
| 47 | + |
| 48 | +func CmdReleases(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ReleasesOptions) error { |
| 49 | + data, err := jira.GetProjectVersionsPaginated(o, globals.Endpoint.Value, opts.Project, opts.Status, opts.Query, opts.OrderBy) |
| 50 | + if err != nil { |
| 51 | + return err |
| 52 | + } |
| 53 | + if err := opts.PrintTemplate(data); err != nil { |
| 54 | + return err |
| 55 | + } |
| 56 | + return nil |
| 57 | +} |
0 commit comments