Added a few fields, added color options

This commit is contained in:
Olivier Tremblay 2016-05-25 17:00:44 -04:00
parent b5c1189de8
commit 6adb5c4920
No known key found for this signature in database
GPG key ID: 1A9FE7C1DFF65CB0
5 changed files with 67 additions and 9 deletions

View file

@ -54,6 +54,7 @@ func (ecmd *EditCmd) Edit(taskKey string) error {
} }
const EDIT_TEMPLATE = `Summary: {{.Fields.Summary}} const EDIT_TEMPLATE = `Summary: {{.Fields.Summary}}
Description: {{.Fields.Description}}` Description: {{.Fields.Description}}
`
var editTmpl = template.Must(template.New("editTmpl").Parse(EDIT_TEMPLATE)) var editTmpl = template.Must(template.New("editTmpl").Parse(EDIT_TEMPLATE))

View file

@ -8,13 +8,11 @@ import (
"os" "os"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"strings"
) )
func main() { func main() {
err := godotenv.Load(".jklrc", fmt.Sprintf("%s/.jklrc", os.Getenv("HOME"))) findRCFile()
if err != nil {
log.Fatalln(err)
}
flag.Parse() flag.Parse()
if len(flag.Args()) == 0 { if len(flag.Args()) == 0 {
fmt.Print(usage) fmt.Print(usage)
@ -25,6 +23,21 @@ func main() {
} }
} }
func findRCFile() {
dir, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}
path := strings.Split(dir, "/")
for i := len(path) - 1; i > 0; i-- {
err := godotenv.Load(strings.Join(path[0:i], "/") + ".jklrc")
if err == nil {
return
}
}
log.Fatalln("No .jklrc found")
}
func runcmd(args []string) error { func runcmd(args []string) error {
switch args[0] { switch args[0] {
case "list": case "list":

View file

@ -7,6 +7,7 @@ import (
"text/template" "text/template"
"fmt"
"otremblay.com/jkl" "otremblay.com/jkl"
) )
@ -14,16 +15,43 @@ var listTemplateStr string
var listTemplate *template.Template var listTemplate *template.Template
func init() { func init() {
flag.StringVar(&listTemplateStr, "listTemplate", "{{.Key}}\t({{.Fields.IssueType.Name}}{{if .Fields.Parent}} of {{.Fields.Parent.Key}}{{end}})\t{{.Fields.Summary}}\n", "Go template used in list command") 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)) listTemplate = template.Must(template.New("listTemplate").Parse(listTemplateStr))
} }
type listissue jkl.Issue
func (l *listissue) Color() string {
if os.Getenv("JKLNOCOLOR") == "true" {
return ""
}
if strings.Contains(os.Getenv("RED_ISSUE_STATUSES"), l.Fields.Status.Name) {
return "\x1b[31m"
}
if strings.Contains(os.Getenv("GREEN_ISSUE_STATUSES"), l.Fields.Status.Name) {
return "\x1b[32m"
}
if strings.Contains(os.Getenv("BLUE_ISSUE_STATUSES"), l.Fields.Status.Name) {
return "\x1b[34m"
}
if strings.Contains(os.Getenv("YELLOW_ISSUE_STATUSES"), l.Fields.Status.Name) || os.Getenv("YELLOW_ISSUE_STATUSES") == "default" {
return "\x1b[33m"
}
return ""
}
func List(args []string) error { func List(args []string) error {
if issues, err := jkl.List(strings.Join(args, " ")); err != nil { if issues, err := jkl.List(strings.Join(args, " ")); err != nil {
return err return err
} else { } else {
for _, issue := range issues { for _, issue := range issues {
listTemplate.Execute(os.Stdout, issue) var li listissue
li = listissue(*issue)
err := listTemplate.Execute(os.Stdout, &li)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
} }
} }
return nil return nil

View file

@ -10,9 +10,13 @@ import (
type TaskCmd struct{} type TaskCmd struct{}
func (t *TaskCmd) Handle(args []string) error { func (t *TaskCmd) Handle(args []string) error {
if len(args) == 1 { c := len(args)
if c == 1 {
return t.Get(args[0]) return t.Get(args[0])
} }
if c == 2 {
return t.Transition(args[0], args[1])
}
return ErrTaskSubCommandNotFound return ErrTaskSubCommandNotFound
} }
@ -26,3 +30,7 @@ func (t *TaskCmd) Get(taskKey string) error {
fmt.Println(issue) fmt.Println(issue)
return nil return nil
} }
func (t *TaskCmd) Transition(taskKey, transition string) error {
return nil
}

View file

@ -31,13 +31,19 @@ type CommentColl struct {
Comments []Comment Comments []Comment
} }
type Status struct {
Name string
}
type Fields struct { type Fields struct {
*IssueType `json:"issuetype,omitempty"` *IssueType `json:"issuetype,omitempty"`
Assignee *Author `json:",omitempty"`
Project *Project `json:"project,omitempty"` Project *Project `json:"project,omitempty"`
Summary string `json:"summary,omitempty"` Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
Comment *CommentColl `json:"comment,omitempty"` Comment *CommentColl `json:"comment,omitempty"`
Parent *Issue `json:",omitempty"` Parent *Issue `json:",omitempty"`
Status *Status `json:",omitempty"`
} }
type Issue struct { type Issue struct {
Key string `json:"key,omitempty"` Key string `json:"key,omitempty"`
@ -61,7 +67,9 @@ var commentTemplate = `{{if .Fields.Comment }}{{range .Fields.Comment.Comments}}
{{end}}{{end}}` {{end}}{{end}}`
var issueTmplTxt = "\x1b[1m{{.Key}}\x1b[0m\t[{{.Fields.IssueType.Name}}]\t{{.Fields.Summary}}\n\n" + var issueTmplTxt = "\x1b[1m{{.Key}}\x1b[0m\t{{if .Fields.IssueType}}[{{.Fields.IssueType.Name}}]{{end}}\t{{.Fields.Summary}}\n\n" +
"\x1b[1mStatus\x1b[0m:\t {{.Fields.Status.Name}}\n" +
"\x1b[1mAssignee:\x1b[0m\t{{.Fields.Assignee.Name}}\n\n" +
"\x1b[1mDescription:\x1b[0m {{.Fields.Description}} \n\n" + "\x1b[1mDescription:\x1b[0m {{.Fields.Description}} \n\n" +
"\x1b[1mComments:\x1b[0m\n\n" + commentTemplate "\x1b[1mComments:\x1b[0m\n\n" + commentTemplate