feat: rename create and delete commands to add and del
This commit is contained in:
70
cmd/add.go
Normal file
70
cmd/add.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"axolotl/db"
|
||||
"axolotl/models"
|
||||
"axolotl/output"
|
||||
"axolotl/service"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var cDue, cContent string
|
||||
var cTags, cRels []string
|
||||
|
||||
var addCmd = &cobra.Command{
|
||||
Use: "add <title>", Short: "Create a new node", Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
d, err := db.GetDB()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !slices.ContainsFunc(cTags, func(e string) bool { return strings.HasPrefix(e, "_type::") }) {
|
||||
cTags = append(cTags, "_type::issue")
|
||||
}
|
||||
if slices.Contains(cTags, "_type::issue") && !slices.ContainsFunc(cTags, func(e string) bool { return strings.HasPrefix(e, "_status::") }) {
|
||||
cTags = append(cTags, "_status::open")
|
||||
}
|
||||
|
||||
rels := make(map[models.RelType][]string)
|
||||
relNamespace := false
|
||||
for _, r := range cRels {
|
||||
rt, tgt, err := parseRelFlag(r)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return
|
||||
}
|
||||
if rt == models.RelInNamespace {
|
||||
relNamespace = true
|
||||
}
|
||||
rels[rt] = append(rels[rt], tgt)
|
||||
}
|
||||
if !relNamespace {
|
||||
rels[models.RelInNamespace] = append(rels[models.RelInNamespace], cfg.GetUser())
|
||||
}
|
||||
|
||||
svc := service.NewSQLiteNodeService(d.DB, cfg.GetUser())
|
||||
if n, err := svc.Create(args[0], cContent, cDue, cTags, rels); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to create:", err)
|
||||
} else {
|
||||
output.PrintNode(cmd.OutOrStdout(), n, jsonFlag)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(addCmd)
|
||||
addPropertyFlags(addCmd)
|
||||
addCmd.Flags().Set("type", "issue")
|
||||
f := addCmd.Flags()
|
||||
f.StringVar(&cDue, "due", "", "")
|
||||
f.StringVar(&cContent, "content", "", "")
|
||||
f.StringArrayVar(&cTags, "tag", nil, "")
|
||||
f.StringArrayVar(&cRels, "rel", nil, "")
|
||||
}
|
||||
Reference in New Issue
Block a user