mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-23 14:28:27 +02:00
set JIRA_OPERATION when parsing configs. Use figtree config types for options to make defaulting work
This commit is contained in:
+1
-1
@@ -51,7 +51,7 @@ func (jc *JiraCli) CmdAssign(opts *AssignOptions) error {
|
||||
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -3,6 +3,8 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -17,7 +19,7 @@ type BlockOptions struct {
|
||||
func (jc *JiraCli) CmdBlockRegistry() *CommandRegistryEntry {
|
||||
opts := BlockOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "edit",
|
||||
Template: figtree.NewStringOption("edit"),
|
||||
},
|
||||
LinkIssueRequest: jiradata.LinkIssueRequest{
|
||||
Type: &jiradata.IssueLinkType{
|
||||
@@ -67,7 +69,7 @@ func (jc *JiraCli) CmdBlock(opts *BlockOptions) error {
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Blocker, jc.Endpoint, opts.Blocker)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
if err := jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue}); err != nil {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Blocker})
|
||||
}
|
||||
|
||||
+19
-16
@@ -36,12 +36,12 @@ type Exit struct {
|
||||
}
|
||||
|
||||
type GlobalOptions struct {
|
||||
Browse bool `json:"browse,omitempty" yaml:"browse,omitempty"`
|
||||
Editor string `json:"editor,omitempty" yaml:"editor,omitempty"`
|
||||
SkipEditing bool `json:"noedit,omitempty" yaml:"noedit,omitempty"`
|
||||
PasswordSource string `json:"password-source,omitempty" yaml:"password-source,omitempty"`
|
||||
Template string `json:"template,omitempty" yaml:"template,omitempty"`
|
||||
User string `json:"user,omitempty", yaml:"user,omitempty"`
|
||||
Browse figtree.BoolOption `json:"browse,omitempty" yaml:"browse,omitempty"`
|
||||
Editor figtree.StringOption `json:"editor,omitempty" yaml:"editor,omitempty"`
|
||||
SkipEditing figtree.BoolOption `json:"noedit,omitempty" yaml:"noedit,omitempty"`
|
||||
PasswordSource figtree.StringOption `json:"password-source,omitempty" yaml:"password-source,omitempty"`
|
||||
Template figtree.StringOption `json:"template,omitempty" yaml:"template,omitempty"`
|
||||
User figtree.StringOption `json:"user,omitempty", yaml:"user,omitempty"`
|
||||
}
|
||||
|
||||
type CommandRegistryEntry struct {
|
||||
@@ -111,26 +111,29 @@ func (jc *JiraCli) Register(app *kingpin.Application, reg []CommandRegistry) {
|
||||
func (jc *JiraCli) GlobalUsage(cmd *kingpin.CmdClause, opts *GlobalOptions) error {
|
||||
jc.LoadConfigs(cmd, opts)
|
||||
cmd.PreAction(func(_ *kingpin.ParseContext) error {
|
||||
os.Setenv("JIRA_OPERATION", cmd.FullCommand())
|
||||
fig := figtree.NewFigTree()
|
||||
fig.EnvPrefix = "JIRA"
|
||||
// populate JiraCli fields if defined in configs (ie for Endpoint)
|
||||
if err := fig.LoadAllConfigs(path.Join(jc.ConfigDir, "config.yml"), jc); err != nil {
|
||||
return err
|
||||
}
|
||||
if opts.User == "" {
|
||||
opts.User = os.Getenv("USER")
|
||||
if opts.User.Value == "" {
|
||||
opts.User = figtree.NewStringOption(os.Getenv("USER"))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
cmd.Flag("endpoint", "URI to use for Jira").Short('e').StringVar(&jc.Endpoint)
|
||||
cmd.Flag("user", "Login mame used for authentication with Jira service").Short('u').StringVar(&opts.User)
|
||||
cmd.Flag("user", "Login mame used for authentication with Jira service").Short('u').SetValue(&opts.User)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (jc *JiraCli) LoadConfigs(cmd *kingpin.CmdClause, opts interface{}) {
|
||||
cmd.PreAction(func(_ *kingpin.ParseContext) error {
|
||||
os.Setenv("JIRA_OPERATION", cmd.FullCommand())
|
||||
fig := figtree.NewFigTree()
|
||||
fig.EnvPrefix = "JIRA"
|
||||
fig.Defaults = opts
|
||||
// load command specific configs first
|
||||
if err := fig.LoadAllConfigs(path.Join(jc.ConfigDir, strings.Join(strings.Fields(cmd.FullCommand()), "_")+".yml"), opts); err != nil {
|
||||
return err
|
||||
@@ -141,27 +144,27 @@ func (jc *JiraCli) LoadConfigs(cmd *kingpin.CmdClause, opts interface{}) {
|
||||
}
|
||||
|
||||
func (jc *JiraCli) BrowseUsage(cmd *kingpin.CmdClause, opts *GlobalOptions) {
|
||||
cmd.Flag("browse", "Open issue(s) in browser after operation").Short('b').BoolVar(&opts.Browse)
|
||||
cmd.Flag("browse", "Open issue(s) in browser after operation").Short('b').SetValue(&opts.Browse)
|
||||
}
|
||||
|
||||
func (jc *JiraCli) EditorUsage(cmd *kingpin.CmdClause, opts *GlobalOptions) {
|
||||
cmd.Flag("editor", "Editor to use").StringVar(&opts.Editor)
|
||||
cmd.Flag("editor", "Editor to use").SetValue(&opts.Editor)
|
||||
}
|
||||
|
||||
func (jc *JiraCli) TemplateUsage(cmd *kingpin.CmdClause, opts *GlobalOptions) {
|
||||
cmd.Flag("template", "Template to use for output").Short('t').StringVar(&opts.Template)
|
||||
cmd.Flag("template", "Template to use for output").Short('t').SetValue(&opts.Template)
|
||||
}
|
||||
|
||||
func (o *GlobalOptions) editFile(fileName string) (changes bool, err error) {
|
||||
var editor string
|
||||
for _, ed := range []string{o.Editor, os.Getenv("JIRA_EDITOR"), os.Getenv("EDITOR"), "vim"} {
|
||||
for _, ed := range []string{o.Editor.Value, os.Getenv("JIRA_EDITOR"), os.Getenv("EDITOR"), "vim"} {
|
||||
if ed != "" {
|
||||
editor = ed
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if o.SkipEditing {
|
||||
if o.SkipEditing.Value {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -216,7 +219,7 @@ func (o *GlobalOptions) editFile(fileName string) (changes bool, err error) {
|
||||
}
|
||||
|
||||
func (jc *JiraCli) editLoop(opts *GlobalOptions, input interface{}, output interface{}, submit func() error) error {
|
||||
tmpFile, err := jc.tmpTemplate(opts.Template, input)
|
||||
tmpFile, err := jc.tmpTemplate(opts.Template.Value, input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -240,7 +243,7 @@ func (jc *JiraCli) editLoop(opts *GlobalOptions, input interface{}, output inter
|
||||
}
|
||||
|
||||
for {
|
||||
if !opts.SkipEditing {
|
||||
if !opts.SkipEditing.Value {
|
||||
changes, err := opts.editFile(tmpFile)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
|
||||
+4
-2
@@ -3,6 +3,8 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -16,7 +18,7 @@ type CommentOptions struct {
|
||||
func (jc *JiraCli) CmdCommentRegistry() *CommandRegistryEntry {
|
||||
opts := CommentOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "comment",
|
||||
Template: figtree.NewStringOption("comment"),
|
||||
},
|
||||
Overrides: map[string]string{},
|
||||
}
|
||||
@@ -65,7 +67,7 @@ func (jc *JiraCli) CmdComment(opts *CommentOptions) error {
|
||||
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -15,7 +17,7 @@ type ComponentAddOptions struct {
|
||||
func (jc *JiraCli) CmdComponentAddRegistry() *CommandRegistryEntry {
|
||||
opts := ComponentAddOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "component-add",
|
||||
Template: figtree.NewStringOption("component-add"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -36,7 +38,7 @@ func (jc *JiraCli) CmdComponentAddUsage(cmd *kingpin.CmdClause, opts *ComponentA
|
||||
}
|
||||
jc.EditorUsage(cmd, &opts.GlobalOptions)
|
||||
jc.TemplateUsage(cmd, &opts.GlobalOptions)
|
||||
cmd.Flag("noedit", "Disable opening the editor").BoolVar(&opts.SkipEditing)
|
||||
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
|
||||
cmd.Flag("project", "project to create component in").Short('p').StringVar(&opts.Project)
|
||||
cmd.Flag("name", "name of component").Short('n').StringVar(&opts.Name)
|
||||
cmd.Flag("description", "description of component").Short('d').StringVar(&opts.Description)
|
||||
|
||||
@@ -3,6 +3,8 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
@@ -14,7 +16,7 @@ type ComponentsOptions struct {
|
||||
func (jc *JiraCli) CmdComponentsRegistry() *CommandRegistryEntry {
|
||||
opts := ComponentsOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "components",
|
||||
Template: figtree.NewStringOption("components"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -48,5 +50,5 @@ func (jc *JiraCli) CmdComponents(opts *ComponentsOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jc.runTemplate(opts.Template, data, nil)
|
||||
return jc.runTemplate(opts.Template.Value, data, nil)
|
||||
}
|
||||
|
||||
+6
-4
@@ -3,6 +3,8 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -18,7 +20,7 @@ type CreateOptions struct {
|
||||
func (jc *JiraCli) CmdCreateRegistry() *CommandRegistryEntry {
|
||||
opts := CreateOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "create",
|
||||
Template: figtree.NewStringOption("create"),
|
||||
},
|
||||
Overrides: map[string]string{},
|
||||
}
|
||||
@@ -41,7 +43,7 @@ func (jc *JiraCli) CmdCreateUsage(cmd *kingpin.CmdClause, opts *CreateOptions) e
|
||||
jc.BrowseUsage(cmd, &opts.GlobalOptions)
|
||||
jc.EditorUsage(cmd, &opts.GlobalOptions)
|
||||
jc.TemplateUsage(cmd, &opts.GlobalOptions)
|
||||
cmd.Flag("noedit", "Disable opening the editor").BoolVar(&opts.SkipEditing)
|
||||
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
|
||||
cmd.Flag("project", "project to create issue in").Short('p').StringVar(&opts.Project)
|
||||
cmd.Flag("issuetype", "issuetype in to create").Short('i').StringVar(&opts.IssueType)
|
||||
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
|
||||
@@ -75,7 +77,7 @@ func (jc *JiraCli) CmdCreate(opts *CreateOptions) error {
|
||||
}
|
||||
input.Overrides["project"] = opts.Project
|
||||
input.Overrides["issuetype"] = opts.IssueType
|
||||
input.Overrides["user"] = opts.User
|
||||
input.Overrides["user"] = opts.User.Value
|
||||
|
||||
var issueResp *jiradata.IssueCreateResponse
|
||||
err = jc.editLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error {
|
||||
@@ -88,7 +90,7 @@ func (jc *JiraCli) CmdCreate(opts *CreateOptions) error {
|
||||
|
||||
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, jc.Endpoint, issueResp.Key)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, issueResp.Key})
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package jiracli
|
||||
|
||||
import kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
import (
|
||||
"github.com/coryb/figtree"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type CreateMetaOptions struct {
|
||||
GlobalOptions
|
||||
@@ -11,7 +14,7 @@ type CreateMetaOptions struct {
|
||||
func (jc *JiraCli) CmdCreateMetaRegistry() *CommandRegistryEntry {
|
||||
opts := CreateMetaOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "createmeta",
|
||||
Template: figtree.NewStringOption("createmeta"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -45,5 +48,5 @@ func (jc *JiraCli) CmdCreateMeta(opts *CreateMetaOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jc.runTemplate(opts.Template, createMeta, nil)
|
||||
return jc.runTemplate(opts.Template.Value, createMeta, nil)
|
||||
}
|
||||
|
||||
+4
-2
@@ -3,6 +3,8 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -17,7 +19,7 @@ type DupOptions struct {
|
||||
func (jc *JiraCli) CmdDupRegistry() *CommandRegistryEntry {
|
||||
opts := DupOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "edit",
|
||||
Template: figtree.NewStringOption("edit"),
|
||||
},
|
||||
LinkIssueRequest: jiradata.LinkIssueRequest{
|
||||
Type: &jiradata.IssueLinkType{
|
||||
@@ -88,7 +90,7 @@ func (jc *JiraCli) CmdDup(opts *DupOptions) error {
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, jc.Endpoint, opts.OutwardIssue.Key)
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, jc.Endpoint, opts.InwardIssue.Key)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
if err := jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.OutwardIssue.Key}); err != nil {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.InwardIssue.Key})
|
||||
}
|
||||
|
||||
+6
-4
@@ -3,6 +3,8 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
|
||||
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
@@ -19,7 +21,7 @@ type EditOptions struct {
|
||||
func (jc *JiraCli) CmdEditRegistry() *CommandRegistryEntry {
|
||||
opts := EditOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "edit",
|
||||
Template: figtree.NewStringOption("edit"),
|
||||
},
|
||||
Overrides: map[string]string{},
|
||||
}
|
||||
@@ -42,7 +44,7 @@ func (jc *JiraCli) CmdEditUsage(cmd *kingpin.CmdClause, opts *EditOptions) error
|
||||
jc.BrowseUsage(cmd, &opts.GlobalOptions)
|
||||
jc.EditorUsage(cmd, &opts.GlobalOptions)
|
||||
jc.TemplateUsage(cmd, &opts.GlobalOptions)
|
||||
cmd.Flag("noedit", "Disable opening the editor").BoolVar(&opts.SkipEditing)
|
||||
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
|
||||
cmd.Flag("query", "Jira Query Language (JQL) expression for the search to edit multiple issues").Short('q').StringVar(&opts.Query)
|
||||
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
|
||||
opts.Overrides["comment"] = flagValue(ctx, "comment")
|
||||
@@ -84,7 +86,7 @@ func (jc *JiraCli) CmdEdit(opts *EditOptions) error {
|
||||
}
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
}
|
||||
@@ -111,7 +113,7 @@ func (jc *JiraCli) CmdEdit(opts *EditOptions) error {
|
||||
}
|
||||
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, jc.Endpoint, issueData.Key)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, issueData.Key})
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -1,6 +1,9 @@
|
||||
package jiracli
|
||||
|
||||
import kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
import (
|
||||
"github.com/coryb/figtree"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type EditMetaOptions struct {
|
||||
GlobalOptions
|
||||
@@ -11,7 +14,7 @@ func (jc *JiraCli) CmdEditMetaRegistry() *CommandRegistryEntry {
|
||||
|
||||
opts := EditMetaOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "editmeta",
|
||||
Template: figtree.NewStringOption("editmeta"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -42,10 +45,10 @@ func (jc *JiraCli) CmdEditMeta(opts *EditMetaOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := jc.runTemplate(opts.Template, editMeta, nil); err != nil {
|
||||
if err := jc.runTemplate(opts.Template.Value, editMeta, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
return nil
|
||||
|
||||
+6
-3
@@ -1,10 +1,13 @@
|
||||
package jiracli
|
||||
|
||||
import kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
import (
|
||||
"github.com/coryb/figtree"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
func (jc *JiraCli) CmdFieldsRegistry() *CommandRegistryEntry {
|
||||
opts := GlobalOptions{
|
||||
Template: "fields",
|
||||
Template: figtree.NewStringOption("fields"),
|
||||
}
|
||||
return &CommandRegistryEntry{
|
||||
"Prints all fields, both System and Custom",
|
||||
@@ -25,5 +28,5 @@ func (jc *JiraCli) CmdFields(opts *GlobalOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jc.runTemplate(opts.Template, data, nil)
|
||||
return jc.runTemplate(opts.Template.Value, data, nil)
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@ type IssueLinkOptions struct {
|
||||
|
||||
func (jc *JiraCli) CmdIssueLinkRegistry() *CommandRegistryEntry {
|
||||
opts := IssueLinkOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "edit",
|
||||
},
|
||||
LinkIssueRequest: jiradata.LinkIssueRequest{
|
||||
Type: &jiradata.IssueLinkType{},
|
||||
InwardIssue: &jiradata.IssueRef{},
|
||||
@@ -64,7 +61,7 @@ func (jc *JiraCli) CmdIssueLink(opts *IssueLinkOptions) error {
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, jc.Endpoint, opts.InwardIssue.Key)
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, jc.Endpoint, opts.OutwardIssue.Key)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
if err := jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.OutwardIssue.Key}); err != nil {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.InwardIssue.Key})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package jiracli
|
||||
|
||||
import kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
import (
|
||||
"github.com/coryb/figtree"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
func (jc *JiraCli) CmdIssueLinkTypesRegistry() *CommandRegistryEntry {
|
||||
opts := GlobalOptions{
|
||||
Template: "issuelinktypes",
|
||||
Template: figtree.NewStringOption("issuelinktypes"),
|
||||
}
|
||||
|
||||
return &CommandRegistryEntry{
|
||||
@@ -32,5 +35,5 @@ func (jc *JiraCli) CmdIssueLinkTypes(opts *GlobalOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jc.runTemplate(opts.Template, data, nil)
|
||||
return jc.runTemplate(opts.Template.Value, data, nil)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
@@ -14,7 +16,7 @@ type IssueTypesOptions struct {
|
||||
func (jc *JiraCli) CmdIssueTypesRegistry() *CommandRegistryEntry {
|
||||
opts := IssueTypesOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "issuetypes",
|
||||
Template: figtree.NewStringOption("issuetypes"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -48,5 +50,5 @@ func (jc *JiraCli) CmdIssueTypes(opts *IssueTypesOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jc.runTemplate(opts.Template, data, nil)
|
||||
return jc.runTemplate(opts.Template.Value, data, nil)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func (jc *JiraCli) CmdLabelsAdd(opts *LabelsAddOptions) error {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -55,7 +55,7 @@ func (jc *JiraCli) CmdLabelsRemove(opts *LabelsRemoveOptions) error {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -52,7 +52,7 @@ func (jc *JiraCli) CmdLabelsSet(opts *LabelsSetOptions) error {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
return nil
|
||||
|
||||
+6
-2
@@ -1,6 +1,7 @@
|
||||
package jiracli
|
||||
|
||||
import (
|
||||
"github.com/coryb/figtree"
|
||||
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -13,7 +14,7 @@ type ListOptions struct {
|
||||
func (jc *JiraCli) CmdListRegistry() *CommandRegistryEntry {
|
||||
opts := ListOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "list",
|
||||
Template: figtree.NewStringOption("list"),
|
||||
},
|
||||
SearchOptions: jira.SearchOptions{
|
||||
MaxResults: 500,
|
||||
@@ -34,7 +35,9 @@ func (jc *JiraCli) CmdListRegistry() *CommandRegistryEntry {
|
||||
}
|
||||
|
||||
func (jc *JiraCli) CmdListUsage(cmd *kingpin.CmdClause, opts *ListOptions) error {
|
||||
log.Debugf("Configs: %#v", opts)
|
||||
jc.LoadConfigs(cmd, opts)
|
||||
log.Debugf("Configs: %#v", opts)
|
||||
if err := jc.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -54,9 +57,10 @@ func (jc *JiraCli) CmdListUsage(cmd *kingpin.CmdClause, opts *ListOptions) error
|
||||
|
||||
// List will query jira and send data to "list" template
|
||||
func (jc *JiraCli) CmdList(opts *ListOptions) error {
|
||||
log.Debugf("Configs: %#v", opts)
|
||||
data, err := jc.Search(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jc.runTemplate(opts.Template, data, nil)
|
||||
return jc.runTemplate(opts.Template.Value, data, nil)
|
||||
}
|
||||
|
||||
+9
-9
@@ -12,21 +12,21 @@ import (
|
||||
|
||||
func (o *GlobalOptions) ProvideAuthParams() *jiradata.AuthParams {
|
||||
return &jiradata.AuthParams{
|
||||
Username: o.User,
|
||||
Username: o.User.Value,
|
||||
Password: o.GetPass(),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *GlobalOptions) GetPass() string {
|
||||
passwd := ""
|
||||
if o.PasswordSource != "" {
|
||||
if o.PasswordSource == "keyring" {
|
||||
if o.PasswordSource.Value != "" {
|
||||
if o.PasswordSource.Value == "keyring" {
|
||||
var err error
|
||||
passwd, err = keyringGet(o.User)
|
||||
passwd, err = keyringGet(o.User.Value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else if o.PasswordSource == "pass" {
|
||||
} else if o.PasswordSource.Value == "pass" {
|
||||
if bin, err := exec.LookPath("pass"); err == nil {
|
||||
buf := bytes.NewBufferString("")
|
||||
cmd := exec.Command(bin, fmt.Sprintf("GoJira/%s", o.User))
|
||||
@@ -56,14 +56,14 @@ func (o *GlobalOptions) GetPass() string {
|
||||
}
|
||||
|
||||
func (o *GlobalOptions) SetPass(passwd string) error {
|
||||
if o.PasswordSource == "keyring" {
|
||||
if o.PasswordSource.Value == "keyring" {
|
||||
// save password in keychain so that it can be used for subsequent http requests
|
||||
err := keyringSet(o.User, passwd)
|
||||
err := keyringSet(o.User.Value, passwd)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to set password in keyring: %s", err)
|
||||
return err
|
||||
}
|
||||
} else if o.PasswordSource == "pass" {
|
||||
} else if o.PasswordSource.Value == "pass" {
|
||||
if bin, err := exec.LookPath("pass"); err == nil {
|
||||
log.Debugf("using %s", bin)
|
||||
passName := fmt.Sprintf("GoJira/%s", o.User)
|
||||
@@ -84,7 +84,7 @@ func (o *GlobalOptions) SetPass(passwd string) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if o.PasswordSource != "" {
|
||||
} else if o.PasswordSource.Value != "" {
|
||||
return fmt.Errorf("Unknown password-source: %s", o.PasswordSource)
|
||||
}
|
||||
return nil
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ func (jc *JiraCli) CmdRank(opts *RankOptions) error {
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.First, jc.Endpoint, opts.First)
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Second, jc.Endpoint, opts.Second)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
if err := jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.First}); err != nil {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Second})
|
||||
}
|
||||
|
||||
+3
-2
@@ -7,6 +7,7 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
@@ -22,7 +23,7 @@ type RequestOptions struct {
|
||||
func (jc *JiraCli) CmdRequestRegistry() *CommandRegistryEntry {
|
||||
opts := RequestOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "request",
|
||||
Template: figtree.NewStringOption("request"),
|
||||
},
|
||||
Method: "GET",
|
||||
}
|
||||
@@ -85,5 +86,5 @@ func (jc *JiraCli) CmdRequest(opts *RequestOptions) error {
|
||||
return fmt.Errorf("JSON Parse Error: %s from %q", err, content)
|
||||
}
|
||||
|
||||
return jc.runTemplate(opts.Template, &data, nil)
|
||||
return jc.runTemplate(opts.Template.Value, &data, nil)
|
||||
}
|
||||
|
||||
+6
-4
@@ -3,6 +3,8 @@ package jiracli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -19,7 +21,7 @@ type SubtaskOptions struct {
|
||||
func (jc *JiraCli) CmdSubtaskRegistry() *CommandRegistryEntry {
|
||||
opts := SubtaskOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "subtask",
|
||||
Template: figtree.NewStringOption("subtask"),
|
||||
},
|
||||
IssueType: "Sub-task",
|
||||
Overrides: map[string]string{},
|
||||
@@ -43,7 +45,7 @@ func (jc *JiraCli) CmdSubtaskUsage(cmd *kingpin.CmdClause, opts *SubtaskOptions)
|
||||
jc.BrowseUsage(cmd, &opts.GlobalOptions)
|
||||
jc.EditorUsage(cmd, &opts.GlobalOptions)
|
||||
jc.TemplateUsage(cmd, &opts.GlobalOptions)
|
||||
cmd.Flag("noedit", "Disable opening the editor").BoolVar(&opts.SkipEditing)
|
||||
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
|
||||
cmd.Flag("project", "project to subtask issue in").Short('p').StringVar(&opts.Project)
|
||||
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
|
||||
opts.Overrides["comment"] = flagValue(ctx, "comment")
|
||||
@@ -91,7 +93,7 @@ func (jc *JiraCli) CmdSubtask(opts *SubtaskOptions) error {
|
||||
}
|
||||
input.Overrides["project"] = opts.Project
|
||||
input.Overrides["issuetype"] = opts.IssueType
|
||||
input.Overrides["user"] = opts.User
|
||||
input.Overrides["user"] = opts.User.Value
|
||||
|
||||
var issueResp *jiradata.IssueCreateResponse
|
||||
err = jc.editLoop(&opts.GlobalOptions, &input, &issueUpdate, func() error {
|
||||
@@ -104,7 +106,7 @@ func (jc *JiraCli) CmdSubtask(opts *SubtaskOptions) error {
|
||||
|
||||
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, jc.Endpoint, issueResp.Key)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, issueResp.Key})
|
||||
}
|
||||
return nil
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ func (jc *JiraCli) CmdTakeRegistry() *CommandRegistryEntry {
|
||||
return &CommandRegistryEntry{
|
||||
"Assign issue to yourself",
|
||||
func() error {
|
||||
opts.Assignee = opts.User
|
||||
opts.Assignee = opts.User.Value
|
||||
return jc.CmdAssign(&opts)
|
||||
},
|
||||
func(cmd *kingpin.CmdClause) error {
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -19,7 +21,7 @@ type TransitionOptions struct {
|
||||
func (jc *JiraCli) CmdTransitionRegistry(transition string) *CommandRegistryEntry {
|
||||
opts := TransitionOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "transition",
|
||||
Template: figtree.NewStringOption("transition"),
|
||||
},
|
||||
Transition: transition,
|
||||
Overrides: map[string]string{},
|
||||
@@ -126,7 +128,7 @@ func (jc *JiraCli) CmdTransition(opts *TransitionOptions) error {
|
||||
}
|
||||
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, jc.Endpoint, issueData.Key)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package jiracli
|
||||
|
||||
import kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
import (
|
||||
"github.com/coryb/figtree"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type TransitionsOptions struct {
|
||||
GlobalOptions
|
||||
@@ -10,7 +13,7 @@ type TransitionsOptions struct {
|
||||
func (jc *JiraCli) CmdTransitionsRegistry(defaultTemplate string) *CommandRegistryEntry {
|
||||
opts := TransitionsOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: defaultTemplate,
|
||||
Template: figtree.NewStringOption(defaultTemplate),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -41,10 +44,10 @@ func (jc *JiraCli) CmdTransitions(opts *TransitionsOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := jc.runTemplate(opts.Template, editMeta, nil); err != nil {
|
||||
if err := jc.runTemplate(opts.Template.Value, editMeta, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
return nil
|
||||
|
||||
+4
-3
@@ -1,6 +1,7 @@
|
||||
package jiracli
|
||||
|
||||
import (
|
||||
"github.com/coryb/figtree"
|
||||
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -14,7 +15,7 @@ type ViewOptions struct {
|
||||
func (jc *JiraCli) CmdViewRegistry() *CommandRegistryEntry {
|
||||
opts := ViewOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "view",
|
||||
Template: figtree.NewStringOption("view"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -48,10 +49,10 @@ func (jc *JiraCli) CmdView(opts *ViewOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := jc.runTemplate(opts.Template, data, nil); err != nil {
|
||||
if err := jc.runTemplate(opts.Template.Value, data, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
return nil
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ func (jc *JiraCli) CmdVote(opts *VoteOptions) error {
|
||||
}
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
return nil
|
||||
|
||||
+2
-2
@@ -55,7 +55,7 @@ func (jc *JiraCli) CmdWatchUsage(cmd *kingpin.CmdClause, opts *WatchOptions) err
|
||||
// with the 'remove' flag)
|
||||
func (jc *JiraCli) CmdWatch(opts *WatchOptions) error {
|
||||
if opts.Watcher == "" {
|
||||
opts.Watcher = opts.User
|
||||
opts.Watcher = opts.User.Value
|
||||
}
|
||||
if opts.Action == WatcherAdd {
|
||||
if err := jc.IssueAddWatcher(opts.Issue, opts.Watcher); err != nil {
|
||||
@@ -69,7 +69,7 @@ func (jc *JiraCli) CmdWatch(opts *WatchOptions) error {
|
||||
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue)
|
||||
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package jiracli
|
||||
|
||||
import (
|
||||
"github.com/coryb/figtree"
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -14,7 +15,7 @@ type WorklogAddOptions struct {
|
||||
func (jc *JiraCli) CmdWorklogAddRegistry() *CommandRegistryEntry {
|
||||
opts := WorklogAddOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "worklog",
|
||||
Template: figtree.NewStringOption("worklog"),
|
||||
},
|
||||
}
|
||||
return &CommandRegistryEntry{
|
||||
@@ -35,7 +36,7 @@ func (jc *JiraCli) CmdWorklogAddUsage(cmd *kingpin.CmdClause, opts *WorklogAddOp
|
||||
jc.BrowseUsage(cmd, &opts.GlobalOptions)
|
||||
jc.EditorUsage(cmd, &opts.GlobalOptions)
|
||||
jc.TemplateUsage(cmd, &opts.GlobalOptions)
|
||||
cmd.Flag("noedit", "Disable opening the editor").BoolVar(&opts.SkipEditing)
|
||||
cmd.Flag("noedit", "Disable opening the editor").SetValue(&opts.SkipEditing)
|
||||
cmd.Flag("comment", "Comment message for worklog").Short('m').StringVar(&opts.Comment)
|
||||
cmd.Flag("time-spent", "Time spent working on issue").Short('T').StringVar(&opts.TimeSpent)
|
||||
cmd.Arg("ISSUE", "issue id to fetch worklogs").Required().StringVar(&opts.Issue)
|
||||
@@ -53,7 +54,7 @@ func (jc *JiraCli) CmdWorklogAdd(opts *WorklogAddOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package jiracli
|
||||
|
||||
import kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
import (
|
||||
"github.com/coryb/figtree"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type WorklogListOptions struct {
|
||||
GlobalOptions
|
||||
@@ -10,7 +13,7 @@ type WorklogListOptions struct {
|
||||
func (jc *JiraCli) CmdWorklogListRegistry() *CommandRegistryEntry {
|
||||
opts := WorklogListOptions{
|
||||
GlobalOptions: GlobalOptions{
|
||||
Template: "worklogs",
|
||||
Template: figtree.NewStringOption("worklogs"),
|
||||
},
|
||||
}
|
||||
return &CommandRegistryEntry{
|
||||
@@ -40,10 +43,10 @@ func (jc *JiraCli) CmdWorklogList(opts *WorklogListOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := jc.runTemplate(opts.Template, data, nil); err != nil {
|
||||
if err := jc.runTemplate(opts.Template.Value, data, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if opts.Browse {
|
||||
if opts.Browse.Value {
|
||||
return jc.CmdBrowse(&BrowseOptions{opts.GlobalOptions, opts.Issue})
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user