diff --git a/cmd/jkl/edit.go b/cmd/jkl/edit.go index e5ae795..8589032 100644 --- a/cmd/jkl/edit.go +++ b/cmd/jkl/edit.go @@ -54,6 +54,7 @@ func (ecmd *EditCmd) Edit(taskKey string) error { } const EDIT_TEMPLATE = `Summary: {{.Fields.Summary}} -Description: {{.Fields.Description}}` +Description: {{.Fields.Description}} +` var editTmpl = template.Must(template.New("editTmpl").Parse(EDIT_TEMPLATE)) diff --git a/cmd/jkl/jkl.go b/cmd/jkl/jkl.go index 77f317d..deca4a3 100644 --- a/cmd/jkl/jkl.go +++ b/cmd/jkl/jkl.go @@ -8,13 +8,11 @@ import ( "os" "github.com/joho/godotenv" + "strings" ) func main() { - err := godotenv.Load(".jklrc", fmt.Sprintf("%s/.jklrc", os.Getenv("HOME"))) - if err != nil { - log.Fatalln(err) - } + findRCFile() flag.Parse() if len(flag.Args()) == 0 { 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 { switch args[0] { case "list": diff --git a/cmd/jkl/list.go b/cmd/jkl/list.go index f3dde3a..3f13fc2 100644 --- a/cmd/jkl/list.go +++ b/cmd/jkl/list.go @@ -7,6 +7,7 @@ import ( "text/template" + "fmt" "otremblay.com/jkl" ) @@ -14,16 +15,43 @@ var listTemplateStr string var listTemplate *template.Template 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)) } +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 { if issues, err := jkl.List(strings.Join(args, " ")); err != nil { return err } else { 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 diff --git a/cmd/jkl/task.go b/cmd/jkl/task.go index 6fea0aa..81279b5 100644 --- a/cmd/jkl/task.go +++ b/cmd/jkl/task.go @@ -10,9 +10,13 @@ import ( type TaskCmd struct{} func (t *TaskCmd) Handle(args []string) error { - if len(args) == 1 { + c := len(args) + if c == 1 { return t.Get(args[0]) } + if c == 2 { + return t.Transition(args[0], args[1]) + } return ErrTaskSubCommandNotFound } @@ -26,3 +30,7 @@ func (t *TaskCmd) Get(taskKey string) error { fmt.Println(issue) return nil } + +func (t *TaskCmd) Transition(taskKey, transition string) error { + return nil +} diff --git a/issue.go b/issue.go index 2123309..9de94fd 100644 --- a/issue.go +++ b/issue.go @@ -31,13 +31,19 @@ type CommentColl struct { Comments []Comment } +type Status struct { + Name string +} + type Fields struct { *IssueType `json:"issuetype,omitempty"` + Assignee *Author `json:",omitempty"` Project *Project `json:"project,omitempty"` Summary string `json:"summary,omitempty"` Description string `json:"description,omitempty"` Comment *CommentColl `json:"comment,omitempty"` Parent *Issue `json:",omitempty"` + Status *Status `json:",omitempty"` } type Issue struct { Key string `json:"key,omitempty"` @@ -61,7 +67,9 @@ var commentTemplate = `{{if .Fields.Comment }}{{range .Fields.Comment.Comments}} {{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[1mComments:\x1b[0m\n\n" + commentTemplate