2026-03-26 12:48:47 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"axolotl/output"
|
2026-03-29 18:58:34 +02:00
|
|
|
"axolotl/service"
|
2026-03-26 12:48:47 +00:00
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-31 15:55:47 +02:00
|
|
|
var cDue, cContent, cStatus, cPrio, cType, cNamespace, cAssignee string
|
2026-03-27 02:11:46 +01:00
|
|
|
var cTags, cRels []string
|
2026-03-26 12:48:47 +00:00
|
|
|
|
2026-03-29 19:46:43 +02:00
|
|
|
var addCmd = &cobra.Command{
|
|
|
|
|
Use: "add <title>", Short: "Create a new node", Args: cobra.ExactArgs(1),
|
2026-03-26 12:48:47 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2026-03-29 23:16:44 +02:00
|
|
|
svc, err := service.GetNodeService(cfg)
|
|
|
|
|
if err != nil {
|
2026-03-31 15:55:47 +02:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
|
return
|
2026-03-27 02:11:46 +01:00
|
|
|
}
|
2026-03-29 23:16:44 +02:00
|
|
|
|
2026-03-31 15:55:47 +02:00
|
|
|
input := service.AddInput{
|
|
|
|
|
Title: args[0],
|
|
|
|
|
Content: cContent,
|
|
|
|
|
DueDate: cDue,
|
|
|
|
|
Type: cType,
|
|
|
|
|
Status: cStatus,
|
|
|
|
|
Priority: cPrio,
|
|
|
|
|
Namespace: cNamespace,
|
|
|
|
|
Assignee: cAssignee,
|
|
|
|
|
Tags: cTags,
|
2026-03-26 12:48:47 +00:00
|
|
|
}
|
2026-03-27 02:11:46 +01:00
|
|
|
|
|
|
|
|
for _, r := range cRels {
|
2026-03-31 15:55:47 +02:00
|
|
|
ri, err := parseRelInput(r)
|
2026-03-26 12:48:47 +00:00
|
|
|
if err != nil {
|
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-03-31 15:55:47 +02:00
|
|
|
input.Rels = append(input.Rels, ri)
|
2026-03-28 04:15:36 +01:00
|
|
|
}
|
2026-03-27 02:11:46 +01:00
|
|
|
|
2026-03-31 15:55:47 +02:00
|
|
|
n, err := svc.Add(input)
|
2026-03-29 21:24:09 +02:00
|
|
|
if err != nil {
|
|
|
|
|
fmt.Fprintln(os.Stderr, "failed to create:", err)
|
2026-03-29 23:16:44 +02:00
|
|
|
return
|
2026-03-26 12:48:47 +00:00
|
|
|
}
|
2026-03-29 23:16:44 +02:00
|
|
|
|
|
|
|
|
output.PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag)
|
2026-03-26 12:48:47 +00:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
2026-03-29 19:46:43 +02:00
|
|
|
rootCmd.AddCommand(addCmd)
|
|
|
|
|
f := addCmd.Flags()
|
2026-03-31 15:55:47 +02:00
|
|
|
f.StringVar(&cType, "type", "issue", "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)")
|
2026-03-26 12:48:47 +00:00
|
|
|
}
|