This commit is contained in:
2026-03-26 12:48:47 +00:00
commit 2d4cff717b
21 changed files with 1835 additions and 0 deletions

57
cmd/alias.go Normal file
View File

@@ -0,0 +1,57 @@
package cmd
import (
"axolotl/db"
"axolotl/output"
"fmt"
"os"
"github.com/spf13/cobra"
)
var aliasList bool
var aliasCmd = &cobra.Command{
Use: "alias [name] [command]",
Short: "Manage aliases",
Args: cobra.MaximumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
d, err := db.GetDB()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
if aliasList {
aliases, err := d.ListAliases()
if err != nil {
return
}
output.PrintAliases(cmd.OutOrStdout(), aliases, jsonFlag)
return
}
if len(args) == 0 {
aliases, _ := d.ListAliases()
output.PrintAliases(cmd.OutOrStdout(), aliases, jsonFlag)
return
}
if len(args) == 1 {
a, err := d.GetAlias(args[0])
if err != nil {
fmt.Fprintln(os.Stderr, " alias not found:", args[0])
return
}
fmt.Println(a.Command)
return
}
if err := d.SetAlias(args[0], args[1]); err != nil {
fmt.Fprintln(os.Stderr, " failed to set alias:", err)
return
}
output.PrintSuccess(cmd.OutOrStdout(), "Alias '%s' set", args[0])
},
}
func init() {
rootCmd.AddCommand(aliasCmd)
aliasCmd.Flags().BoolVar(&aliasList, "list", false, "list all aliases")
}

68
cmd/create.go Normal file
View File

@@ -0,0 +1,68 @@
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)")
}

53
cmd/delete.go Normal file
View File

@@ -0,0 +1,53 @@
package cmd
import (
"axolotl/db"
"axolotl/output"
"bufio"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
)
var deleteForce bool
var deleteCmd = &cobra.Command{
Use: "delete <id>",
Short: "Delete a 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
}
id := args[0]
n, err := d.NodeByID(id)
if err != nil {
fmt.Fprintln(os.Stderr, " node not found:", id)
return
}
if !deleteForce {
fmt.Printf(" Delete %s '%s'? [y/N]: ", n.GetType(), n.Title)
reader := bufio.NewReader(os.Stdin)
resp, _ := reader.ReadString('\n')
resp = strings.TrimSpace(strings.ToLower(resp))
if resp != "y" && resp != "yes" {
fmt.Println(" Cancelled.")
return
}
}
if err := d.DeleteNode(id); err != nil {
fmt.Fprintln(os.Stderr, " failed to delete:", err)
return
}
output.PrintDeleted(cmd.OutOrStdout(), id)
},
}
func init() {
rootCmd.AddCommand(deleteCmd)
deleteCmd.Flags().BoolVarP(&deleteForce, "force", "f", false, "skip confirmation")
}

66
cmd/edit.go Normal file
View File

@@ -0,0 +1,66 @@
package cmd
import (
"axolotl/db"
"axolotl/output"
"fmt"
"os"
"os/exec"
"github.com/spf13/cobra"
)
var editCmd = &cobra.Command{
Use: "edit <id>",
Short: "Edit node content in $EDITOR",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
d, err := db.GetDB()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
id := args[0]
n, err := d.NodeByID(id)
if err != nil {
fmt.Fprintln(os.Stderr, "node not found:", id)
return
}
tmp, err := os.CreateTemp("", "ax-*.md")
if err != nil {
fmt.Fprintln(os.Stderr, "failed to create temp file:", err)
return
}
tmp.WriteString(n.Content)
tmp.Close()
defer os.Remove(tmp.Name())
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vi"
}
c := exec.Command(editor, tmp.Name())
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if err := c.Run(); err != nil {
fmt.Fprintln(os.Stderr, "editor failed:", err)
return
}
content, err := os.ReadFile(tmp.Name())
if err != nil {
fmt.Fprintln(os.Stderr, "failed to read temp file:", err)
return
}
if err := d.UpdateNode(id, db.UpdateParams{Content: string(content)}); err != nil {
fmt.Fprintln(os.Stderr, "failed to update:", err)
return
}
n, _ = d.NodeByID(id)
output.PrintNode(cmd.OutOrStdout(), n, jsonFlag)
},
}
func init() {
rootCmd.AddCommand(editCmd)
}

28
cmd/inbox.go Normal file
View File

@@ -0,0 +1,28 @@
package cmd
import (
"axolotl/db"
"axolotl/output"
"github.com/spf13/cobra"
)
var inboxCmd = &cobra.Command{
Use: "inbox",
Short: "Show your inbox",
Run: func(cmd *cobra.Command, args []string) {
d, err := db.GetDB()
user := db.GetCurrentUser()
nodes, err := d.ListNodes(db.ListFilter{
Inbox: user,
})
if err != nil {
return
}
output.PrintNodes(cmd.OutOrStdout(), nodes, jsonFlag)
},
}
func init() {
rootCmd.AddCommand(inboxCmd)
}

38
cmd/init.go Normal file
View File

@@ -0,0 +1,38 @@
package cmd
import (
"axolotl/db"
"axolotl/output"
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
)
var initCmd = &cobra.Command{
Use: "init [path]",
Short: "Initialize a new database",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
path := "."
if len(args) > 0 {
path = args[0]
}
dbPath := filepath.Join(path, ".ax.db")
if _, err := os.Stat(dbPath); err == nil {
fmt.Fprintln(os.Stderr, "database already exists:", dbPath)
os.Exit(1)
}
err := db.Init(dbPath)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to initialize:", err)
os.Exit(1)
}
output.PrintCreated(cmd.OutOrStdout(), dbPath)
},
}
func init() {
rootCmd.AddCommand(initCmd)
}

48
cmd/list.go Normal file
View File

@@ -0,0 +1,48 @@
package cmd
import (
"axolotl/db"
"axolotl/output"
"fmt"
"os"
"github.com/spf13/cobra"
)
var listType, listStatus, listPrio, listNamespace, listTag, listInbox, listAssignee string
var listCmd = &cobra.Command{
Use: "list",
Short: "List nodes",
Run: func(cmd *cobra.Command, args []string) {
d, err := db.GetDB()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
nodes, err := d.ListNodes(db.ListFilter{
Type: listType,
Status: listStatus,
Priority: listPrio,
Namespace: listNamespace,
Tag: listTag,
Inbox: listInbox,
Assignee: listAssignee,
})
if err != nil {
return
}
output.PrintNodes(cmd.OutOrStdout(), nodes, jsonFlag)
},
}
func init() {
rootCmd.AddCommand(listCmd)
listCmd.Flags().StringVar(&listType, "type", "", "filter by type")
listCmd.Flags().StringVar(&listStatus, "status", "", "filter by status")
listCmd.Flags().StringVar(&listPrio, "prio", "", "filter by priority")
listCmd.Flags().StringVar(&listNamespace, "namespace", "", "filter by namespace")
listCmd.Flags().StringVar(&listTag, "tag", "", "filter by tag")
listCmd.Flags().StringVar(&listInbox, "inbox", "", "filter by inbox user")
listCmd.Flags().StringVar(&listAssignee, "assignee", "", "filter by assignee")
}

24
cmd/root.go Normal file
View File

@@ -0,0 +1,24 @@
package cmd
import (
"os"
"github.com/spf13/cobra"
)
var jsonFlag bool
var rootCmd = &cobra.Command{
Use: "ax",
Short: "The axolotl issue tracker",
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
func init() {
rootCmd.PersistentFlags().BoolVar(&jsonFlag, "json", false, "output as JSON")
}

33
cmd/show.go Normal file
View File

@@ -0,0 +1,33 @@
package cmd
import (
"axolotl/db"
"axolotl/output"
"fmt"
"os"
"github.com/spf13/cobra"
)
var showCmd = &cobra.Command{
Use: "show <id>",
Short: "Show node details",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
d, err := db.GetDB()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
n, err := d.NodeByID(args[0])
if err != nil {
fmt.Fprintln(os.Stderr, "node not found:", args[0])
return
}
output.PrintNode(cmd.OutOrStdout(), n, jsonFlag)
},
}
func init() {
rootCmd.AddCommand(showCmd)
}

94
cmd/update.go Normal file
View File

@@ -0,0 +1,94 @@
package cmd
import (
"axolotl/db"
"axolotl/models"
"axolotl/output"
"fmt"
"os"
"github.com/spf13/cobra"
)
var updateTitle, updateContent, updateStatus, updatePrio, updateDue string
var updateClearDue bool
var updateAddTags, updateRemoveTags, updateAddRels, updateRemoveRels []string
var updateCmd = &cobra.Command{
Use: "update <id>",
Short: "Update a 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
}
id := args[0]
addRels := make(map[models.RelType][]string)
removeRels := make(map[models.RelType][]string)
for _, r := range updateAddRels {
relType, target, err := db.ParseRelFlag(r)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
addRels[relType] = append(addRels[relType], target)
}
for _, r := range updateRemoveRels {
relType, target, err := db.ParseRelFlag(r)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
removeRels[relType] = append(removeRels[relType], target)
}
if updateStatus == "done" {
ok, blockers, err := d.CanClose(id)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to check blockers:", err)
return
}
if !ok {
fmt.Fprintf(os.Stderr, "cannot close: blocked by %v\n", blockers)
return
}
}
err = d.UpdateNode(id, db.UpdateParams{
Title: updateTitle,
Content: updateContent,
DueDate: updateDue,
ClearDue: updateClearDue,
Status: updateStatus,
Priority: updatePrio,
AddTags: updateAddTags,
RemoveTags: updateRemoveTags,
AddRels: addRels,
RemoveRels: removeRels,
})
if err != nil {
fmt.Fprintln(os.Stderr, "failed to update:", err)
return
}
n, err := d.NodeByID(id)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to fetch node:", err)
return
}
output.PrintNode(cmd.OutOrStdout(), n, jsonFlag)
},
}
func init() {
rootCmd.AddCommand(updateCmd)
updateCmd.Flags().StringVar(&updateTitle, "title", "", "new title")
updateCmd.Flags().StringVar(&updateContent, "content", "", "new content")
updateCmd.Flags().StringVar(&updateStatus, "status", "", "status (open, done)")
updateCmd.Flags().StringVar(&updatePrio, "prio", "", "priority (high, medium, low)")
updateCmd.Flags().StringVar(&updateDue, "due", "", "due date")
updateCmd.Flags().BoolVar(&updateClearDue, "clear-due", false, "clear due date")
updateCmd.Flags().StringArrayVar(&updateAddTags, "tag", nil, "add tags (repeatable)")
updateCmd.Flags().StringArrayVar(&updateRemoveTags, "tag-remove", nil, "remove tags (repeatable)")
updateCmd.Flags().StringArrayVar(&updateAddRels, "rel", nil, "add relations (type:id, repeatable)")
updateCmd.Flags().StringArrayVar(&updateRemoveRels, "rel-remove", nil, "remove relations (type:id, repeatable)")
}