refactor: simplify service interface to use tags/rels for all node properties
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
35
cmd/add.go
35
cmd/add.go
@@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"axolotl/models"
|
||||
"axolotl/output"
|
||||
"axolotl/service"
|
||||
"fmt"
|
||||
@@ -9,7 +10,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var cDue, cContent, cStatus, cPrio, cType, cNamespace, cAssignee string
|
||||
var cDue, cContent, cType, cStatus, cPrio, cNamespace, cAssignee string
|
||||
var cTags, cRels []string
|
||||
|
||||
var addCmd = &cobra.Command{
|
||||
@@ -22,15 +23,27 @@ var addCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
input := service.AddInput{
|
||||
Title: args[0],
|
||||
Content: cContent,
|
||||
DueDate: cDue,
|
||||
Type: cType,
|
||||
Status: cStatus,
|
||||
Priority: cPrio,
|
||||
Namespace: cNamespace,
|
||||
Assignee: cAssignee,
|
||||
Tags: cTags,
|
||||
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 {
|
||||
@@ -55,7 +68,7 @@ var addCmd = &cobra.Command{
|
||||
func init() {
|
||||
rootCmd.AddCommand(addCmd)
|
||||
f := addCmd.Flags()
|
||||
f.StringVar(&cType, "type", "issue", "node type (issue, note, …)")
|
||||
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")
|
||||
|
||||
29
cmd/list.go
29
cmd/list.go
@@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"axolotl/models"
|
||||
"axolotl/output"
|
||||
"axolotl/service"
|
||||
"fmt"
|
||||
@@ -22,13 +23,27 @@ var listCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
filter := service.ListFilter{
|
||||
Tags: lTags,
|
||||
Status: lStatus,
|
||||
Priority: lPrio,
|
||||
Type: lType,
|
||||
Namespace: lNamespace,
|
||||
Assignee: lAssignee,
|
||||
Mention: lMention,
|
||||
Tags: append([]string{}, lTags...),
|
||||
}
|
||||
|
||||
// Shorthand flags expand to tag prefixes or rel filters.
|
||||
if lStatus != "" {
|
||||
filter.Tags = append(filter.Tags, "_status::"+lStatus)
|
||||
}
|
||||
if lPrio != "" {
|
||||
filter.Tags = append(filter.Tags, "_prio::"+lPrio)
|
||||
}
|
||||
if lType != "" {
|
||||
filter.Tags = append(filter.Tags, "_type::"+lType)
|
||||
}
|
||||
if lNamespace != "" {
|
||||
filter.Rels = append(filter.Rels, service.RelInput{Type: models.RelInNamespace, Target: lNamespace})
|
||||
}
|
||||
if lAssignee != "" {
|
||||
filter.Rels = append(filter.Rels, service.RelInput{Type: models.RelAssignee, Target: lAssignee})
|
||||
}
|
||||
if lMention != "" {
|
||||
filter.Rels = append(filter.Rels, service.RelInput{Type: models.RelMentions, Target: lMention})
|
||||
}
|
||||
|
||||
for _, r := range lRels {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"axolotl/models"
|
||||
"axolotl/output"
|
||||
"axolotl/service"
|
||||
"fmt"
|
||||
@@ -10,10 +11,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
uTitle, uContent, uDue string
|
||||
uClearDue bool
|
||||
uStatus, uPrio, uType, uNamespace, uAssignee string
|
||||
uAddTags, uRmTags, uAddRels, uRmRels []string
|
||||
uTitle, uContent, uDue string
|
||||
uClearDue bool
|
||||
uStatus, uPrio, uType string
|
||||
uNamespace, uAssignee string
|
||||
uAddTags, uRmTags, uAddRels, uRmRels []string
|
||||
)
|
||||
|
||||
var updateCmd = &cobra.Command{
|
||||
@@ -26,7 +28,7 @@ var updateCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
input := service.UpdateInput{
|
||||
AddTags: uAddTags,
|
||||
AddTags: append([]string{}, uAddTags...),
|
||||
RemoveTags: uRmTags,
|
||||
}
|
||||
|
||||
@@ -43,20 +45,22 @@ var updateCmd = &cobra.Command{
|
||||
empty := ""
|
||||
input.DueDate = &empty
|
||||
}
|
||||
|
||||
// Shorthand flags expand to tags or rels.
|
||||
if cmd.Flags().Changed("type") {
|
||||
input.AddTags = append(input.AddTags, "_type::"+uType)
|
||||
}
|
||||
if cmd.Flags().Changed("status") {
|
||||
input.Status = &uStatus
|
||||
input.AddTags = append(input.AddTags, "_status::"+uStatus)
|
||||
}
|
||||
if cmd.Flags().Changed("prio") {
|
||||
input.Priority = &uPrio
|
||||
}
|
||||
if cmd.Flags().Changed("type") {
|
||||
input.Type = &uType
|
||||
input.AddTags = append(input.AddTags, "_prio::"+uPrio)
|
||||
}
|
||||
if cmd.Flags().Changed("namespace") {
|
||||
input.Namespace = &uNamespace
|
||||
input.AddRels = append(input.AddRels, service.RelInput{Type: models.RelInNamespace, Target: uNamespace})
|
||||
}
|
||||
if cmd.Flags().Changed("assignee") {
|
||||
input.Assignee = &uAssignee
|
||||
input.AddRels = append(input.AddRels, service.RelInput{Type: models.RelAssignee, Target: uAssignee})
|
||||
}
|
||||
|
||||
for _, r := range uAddRels {
|
||||
|
||||
Reference in New Issue
Block a user