Some fixes

This commit is contained in:
Olivier Tremblay 2016-05-26 15:33:47 -04:00
parent 5a2f3f98ac
commit 5927b657f9
No known key found for this signature in database
GPG key ID: 1A9FE7C1DFF65CB0
5 changed files with 72 additions and 26 deletions

View file

@ -16,8 +16,8 @@ type EditCmd struct {
file string
}
func NewEditCmd(args []string) (*CreateCmd, error) {
ccmd := &CreateCmd{project: os.Getenv("JIRA_PROJECT")}
func NewEditCmd(args []string) (*EditCmd, error) {
ccmd := &EditCmd{project: os.Getenv("JIRA_PROJECT")}
f := flag.NewFlagSet("x", flag.ExitOnError)
f.StringVar(&ccmd.project, "p", "", "Jira project key")
f.StringVar(&ccmd.file, "f", "filename", "File to get issue description from")

View file

@ -41,7 +41,11 @@ func findRCFile() {
func runcmd(args []string) error {
switch args[0] {
case "list":
return List(flag.Args()[1:])
lcmd, err := NewListCmd(flag.Args()[1:])
if err != nil {
return err
}
return lcmd.List()
case "create":
ccmd, err := NewCreateCmd(flag.Args()[1:])
if err != nil {

View file

@ -12,14 +12,6 @@ import (
"otremblay.com/jkl"
)
var listTemplateStr string
var listTemplate *template.Template
func init() {
flag.StringVar(&listTemplateStr, "listTemplate", "{{.Color}}{{.Key}}{{if .Color}}\x1b[39m{{end}}\t({{.Fields.IssueType.Name}}{{if .Fields.Parent}} of {{.Fields.Parent.Key}}{{end}})\t{{.Fields.Summary}}\t[{{.Fields.Assignee.Name}}]\n", "Go template used in list command")
listTemplate = template.Must(template.New("listTemplate").Parse(listTemplateStr))
}
type listissue jkl.Issue
func (l *listissue) Color() string {
@ -42,14 +34,37 @@ func (l *listissue) Color() string {
return ""
}
func List(args []string) error {
if issues, err := jkl.List(strings.Join(args, " ")); err != nil {
type ListCmd struct {
args []string
tmplstr string
tmpl *template.Template
}
func NewListCmd(args []string) (*ListCmd, error) {
ccmd := &ListCmd{}
f := flag.NewFlagSet("x", flag.ExitOnError)
f.StringVar(&ccmd.tmplstr, "listTemplate", "{{.Color}}{{.Key}}{{if .Color}}\x1b[39m{{end}}\t({{.Fields.IssueType.Name}}{{if .Fields.Parent}} of {{.Fields.Parent.Key}}{{end}})\t{{.Fields.Summary}}\t{{if .Fields.Assignee}}[{{.Fields.Assignee.Name}}]{{end}}\n", "Go template used in list command")
f.Parse(args)
ccmd.args = f.Args()
if len(ccmd.args) == 0 {
proj := os.Getenv("JIRA_PROJECT")
if proj != "" {
proj = fmt.Sprintf(" and project = %s ", proj)
}
ccmd.args = []string{fmt.Sprintf("sprint in openSprints() %s order by rank", proj)}
}
ccmd.tmpl = template.Must(template.New("listTemplate").Parse(ccmd.tmplstr))
return ccmd, nil
}
func (l *ListCmd) List() error {
if issues, err := jkl.List(strings.Join(l.args, " ")); err != nil {
return err
} else {
for _, issue := range issues {
var li listissue
li = listissue(*issue)
err := listTemplate.Execute(os.Stdout, &li)
err := l.tmpl.Execute(os.Stdout, &li)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}