Skip to content

Commit

Permalink
move commands from jiracli package to jiracmd package
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Sep 2, 2017
1 parent de1460d commit 0a5510b
Show file tree
Hide file tree
Showing 40 changed files with 417 additions and 384 deletions.
2 changes: 1 addition & 1 deletion jiracli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (o *GlobalOptions) editFile(fileName string) (changes bool, err error) {
return false, err
}

func editLoop(opts *GlobalOptions, input interface{}, output interface{}, submit func() error) error {
func EditLoop(opts *GlobalOptions, input interface{}, output interface{}, submit func() error) error {
tmpFile, err := tmpTemplate(opts.Template.Value, input)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion jiracli/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Error struct {
error
}

func cliError(cause error) error {
func CliError(cause error) error {
return &Error{
errors.WithStack(cause),
}
Expand Down
35 changes: 0 additions & 35 deletions jiracli/fields.go

This file was deleted.

8 changes: 4 additions & 4 deletions jiracli/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func getTemplate(name string) (string, error) {
} else if b != nil {
return string(b), nil
}
if s, ok := allTemplates[name]; ok {
if s, ok := AllTemplates[name]; ok {
return s, nil
}
return "", fmt.Errorf("No Template found for %q", name)
Expand All @@ -56,7 +56,7 @@ func tmpTemplate(templateName string, data interface{}) (string, error) {
return "", err
}
defer tmpFile.Close()
return tmpFile.Name(), runTemplate(templateName, data, tmpFile)
return tmpFile.Name(), RunTemplate(templateName, data, tmpFile)
}

func TemplateProcessor() *template.Template {
Expand Down Expand Up @@ -155,7 +155,7 @@ func TemplateProcessor() *template.Template {
return template.New("gojira").Funcs(funcs)
}

func runTemplate(templateName string, data interface{}, out io.Writer) error {
func RunTemplate(templateName string, data interface{}, out io.Writer) error {

templateContent, err := getTemplate(templateName)
if err != nil {
Expand Down Expand Up @@ -194,7 +194,7 @@ func runTemplate(templateName string, data interface{}, out io.Writer) error {
return nil
}

var allTemplates = map[string]string{
var AllTemplates = map[string]string{
"component-add": defaultComponentAddTemplate,
"debug": defaultDebugTemplate,
"fields": defaultDebugTemplate,
Expand Down
2 changes: 1 addition & 1 deletion jiracli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func tmpYml(tmpFilePrefix string) (*os.File, error) {
return os.OpenFile(newFileName, os.O_RDWR|os.O_EXCL, 0600)
}

func flagValue(ctx *kingpin.ParseContext, name string) string {
func FlagValue(ctx *kingpin.ParseContext, name string) string {
for _, elem := range ctx.Elements {
if flag, ok := elem.Clause.(*kingpin.FlagClause); ok {
if flag.Model().Name == name {
Expand Down
19 changes: 10 additions & 9 deletions jiracli/assign.go → jiracmd/assign.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
package jiracli
package jiracmd

import (
"fmt"

"github.com/coryb/figtree"
"github.com/coryb/oreo"

jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

type AssignOptions struct {
GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Assignee string `yaml:"assignee,omitempty" json:"assignee,omitempty"`
}

func CmdAssignRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry {
func CmdAssignRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := AssignOptions{}

return &CommandRegistryEntry{
return &jiracli.CommandRegistryEntry{
"Assign user to issue",
func() error {
return CmdAssign(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
LoadConfigs(cmd, fig, &opts)
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdAssignUsage(cmd, &opts)
},
}
}

func CmdAssignUsage(cmd *kingpin.CmdClause, opts *AssignOptions) error {
if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
cmd.Flag("default", "use default user for assignee").PreAction(func(ctx *kingpin.ParseContext) error {
if flagValue(ctx, "default") == "true" {
if jiracli.FlagValue(ctx, "default") == "true" {
opts.Assignee = "-1"
}
return nil
Expand Down
25 changes: 13 additions & 12 deletions jiracli/block.go → jiracmd/block.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package jiracli
package jiracmd

import (
"fmt"

"github.com/coryb/figtree"
"github.com/coryb/oreo"

jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

type BlockOptions struct {
GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiradata.LinkIssueRequest `yaml:",inline" json:",inline" figtree:",inline"`
}

func CmdBlockRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry {
func CmdBlockRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := BlockOptions{
GlobalOptions: GlobalOptions{
GlobalOptions: jiracli.GlobalOptions{
Template: figtree.NewStringOption("edit"),
},
LinkIssueRequest: jiradata.LinkIssueRequest{
Expand All @@ -30,28 +31,28 @@ func CmdBlockRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntr
},
}

return &CommandRegistryEntry{
return &jiracli.CommandRegistryEntry{
"Mark issues as blocker",
func() error {
return CmdBlock(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
LoadConfigs(cmd, fig, &opts)
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdBlockUsage(cmd, &opts)
},
}
}

func CmdBlockUsage(cmd *kingpin.CmdClause, opts *BlockOptions) error {
if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
BrowseUsage(cmd, &opts.GlobalOptions)
EditorUsage(cmd, &opts.GlobalOptions)
TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("comment", "Comment message when marking issue as blocker").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Comment = &jiradata.Comment{
Body: flagValue(ctx, "comment"),
Body: jiracli.FlagValue(ctx, "comment"),
}
return nil
}).String()
Expand Down
15 changes: 8 additions & 7 deletions jiracli/browse.go → jiracmd/browse.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
package jiracli
package jiracmd

import (
"fmt"

"github.com/coryb/figtree"
"github.com/pkg/browser"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

type BrowseOptions struct {
GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}

func CmdBrowseRegistry(fig *figtree.FigTree) *CommandRegistryEntry {
func CmdBrowseRegistry(fig *figtree.FigTree) *jiracli.CommandRegistryEntry {
opts := BrowseOptions{}

return &CommandRegistryEntry{
return &jiracli.CommandRegistryEntry{
"Open issue in browser",
func() error {
return CmdBrowse(&opts)
},
func(cmd *kingpin.CmdClause) error {
LoadConfigs(cmd, fig, &opts)
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdBrowseUsage(cmd, &opts)
},
}
}

func CmdBrowseUsage(cmd *kingpin.CmdClause, opts *BrowseOptions) error {
if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
cmd.Arg("ISSUE", "Issue to browse to").Required().StringVar(&opts.Issue)
Expand Down
27 changes: 14 additions & 13 deletions jiracli/comment.go → jiracmd/comment.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
package jiracli
package jiracmd

import (
"fmt"

"github.com/coryb/figtree"
"github.com/coryb/oreo"

jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

type CommentOptions struct {
GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
jiracli.GlobalOptions `yaml:",inline" json:",inline" figtree:",inline"`
Overrides map[string]string `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
}

func CmdCommentRegistry(fig *figtree.FigTree, o *oreo.Client) *CommandRegistryEntry {
func CmdCommentRegistry(fig *figtree.FigTree, o *oreo.Client) *jiracli.CommandRegistryEntry {
opts := CommentOptions{
GlobalOptions: GlobalOptions{
GlobalOptions: jiracli.GlobalOptions{
Template: figtree.NewStringOption("comment"),
},
Overrides: map[string]string{},
}

return &CommandRegistryEntry{
return &jiracli.CommandRegistryEntry{
"Add comment to issue",
func() error {
return CmdComment(o, &opts)
},
func(cmd *kingpin.CmdClause) error {
LoadConfigs(cmd, fig, &opts)
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdCommentUsage(cmd, &opts)
},
}
}

func CmdCommentUsage(cmd *kingpin.CmdClause, opts *CommentOptions) error {
if err := GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
if err := jiracli.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
BrowseUsage(cmd, &opts.GlobalOptions)
EditorUsage(cmd, &opts.GlobalOptions)
TemplateUsage(cmd, &opts.GlobalOptions)
jiracli.BrowseUsage(cmd, &opts.GlobalOptions)
jiracli.EditorUsage(cmd, &opts.GlobalOptions)
jiracli.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("comment", "Comment message for issue").Short('m').PreAction(func(ctx *kingpin.ParseContext) error {
opts.Overrides["comment"] = flagValue(ctx, "comment")
opts.Overrides["comment"] = jiracli.FlagValue(ctx, "comment")
return nil
}).String()
cmd.Arg("ISSUE", "issue id to update").StringVar(&opts.Issue)
Expand All @@ -60,7 +61,7 @@ func CmdComment(o *oreo.Client, opts *CommentOptions) error {
}{
opts.Overrides,
}
err := editLoop(&opts.GlobalOptions, &input, &comment, func() error {
err := jiracli.EditLoop(&opts.GlobalOptions, &input, &comment, func() error {
_, err := jira.IssueAddComment(o, opts.Endpoint.Value, opts.Issue, &comment)
return err
})
Expand Down
Loading

0 comments on commit 0a5510b

Please sign in to comment.