69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package cmd
|
|
|
|
import (
|
|
"axolotl/db"
|
|
"axolotl/models"
|
|
"axolotl/output"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var createType, createStatus, createPrio, createNamespace string = "issue", "open", "", ""
|
|
var createDue, createContent string
|
|
var createTags, createRels []string
|
|
|
|
var createCmd = &cobra.Command{
|
|
Use: "create <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 createType == "issue" && createStatus == "" {
|
|
createStatus = "open"
|
|
}
|
|
rels := make(map[models.RelType][]string)
|
|
for _, r := range createRels {
|
|
relType, target, err := db.ParseRelFlag(r)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
return
|
|
}
|
|
rels[relType] = append(rels[relType], target)
|
|
}
|
|
n, err := d.CreateNode(db.CreateParams{
|
|
Title: args[0],
|
|
Content: createContent,
|
|
DueDate: createDue,
|
|
Type: createType,
|
|
Status: createStatus,
|
|
Priority: createPrio,
|
|
Namespace: createNamespace,
|
|
Tags: createTags,
|
|
Rels: rels,
|
|
})
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "failed to create:", err)
|
|
return
|
|
}
|
|
output.PrintNode(cmd.OutOrStdout(), n, jsonFlag)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(createCmd)
|
|
createCmd.Flags().StringVar(&createType, "type", "issue", "node type (issue, note, user, namespace)")
|
|
createCmd.Flags().StringVar(&createStatus, "status", "", "status (open, done)")
|
|
createCmd.Flags().StringVar(&createPrio, "prio", "", "priority (high, medium, low)")
|
|
createCmd.Flags().StringVar(&createNamespace, "namespace", "", "namespace")
|
|
createCmd.Flags().StringVar(&createDue, "due", "", "due date")
|
|
createCmd.Flags().StringVar(&createContent, "content", "", "content")
|
|
createCmd.Flags().StringArrayVar(&createTags, "tag", nil, "tags (repeatable)")
|
|
createCmd.Flags().StringArrayVar(&createRels, "rel", nil, "relations (type:id, repeatable)")
|
|
}
|