package cmd import ( "axolotl/models" "axolotl/output" "axolotl/service" "fmt" "os" "github.com/spf13/cobra" ) var cDue, cContent, cType, cStatus, cPrio, cNamespace, cAssignee string var cTags, cRels []string var addCmd = &cobra.Command{ Use: "add ", Short: "Create a new node", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { svc, err := service.GetNodeService(cfg) if err != nil { fmt.Fprintln(os.Stderr, err) return } input := service.AddInput{ Title: args[0], Content: cContent, DueDate: cDue, Tags: append([]string{}, cTags...), } // Shorthand flags expand to tags or rels. if cType != "" { input.Tags = append(input.Tags, "_type::"+cType) } if cStatus != "" { input.Tags = append(input.Tags, "_status::"+cStatus) } if cPrio != "" { input.Tags = append(input.Tags, "_prio::"+cPrio) } if cNamespace != "" { input.Rels = append(input.Rels, service.RelInput{Type: models.RelInNamespace, Target: cNamespace}) } if cAssignee != "" { input.Rels = append(input.Rels, service.RelInput{Type: models.RelAssignee, Target: cAssignee}) } for _, r := range cRels { ri, err := parseRelInput(r) if err != nil { fmt.Fprintln(os.Stderr, err) return } input.Rels = append(input.Rels, ri) } n, err := svc.Add(input) if err != nil { fmt.Fprintln(os.Stderr, "failed to create:", err) return } output.PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag) }, } func init() { rootCmd.AddCommand(addCmd) f := addCmd.Flags() f.StringVar(&cType, "type", "", "node type (issue, note, …)") f.StringVar(&cStatus, "status", "", "initial status (open, done)") f.StringVar(&cPrio, "prio", "", "priority (high, medium, low)") f.StringVar(&cNamespace, "namespace", "", "namespace name or ID") f.StringVar(&cAssignee, "assignee", "", "assignee username or ID") f.StringVar(&cDue, "due", "", "due date") f.StringVar(&cContent, "content", "", "node body") f.StringArrayVar(&cTags, "tag", nil, "custom tags") f.StringArrayVar(&cRels, "rel", nil, "additional relations (type:target)") }