refactor: convert inbox command to default alias
This commit is contained in:
30
cmd/inbox.go
30
cmd/inbox.go
@@ -1,30 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"axolotl/db"
|
||||
"axolotl/output"
|
||||
"axolotl/service"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"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()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return
|
||||
}
|
||||
svc := service.NewSQLiteNodeService(d.DB, cfg.GetUser())
|
||||
if nodes, err := svc.List(service.WithMentions(cfg.GetUser())); err == nil {
|
||||
output.PrintNodes(cmd.OutOrStdout(), nodes, jsonFlag)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(inboxCmd)
|
||||
}
|
||||
15
cmd/list.go
15
cmd/list.go
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
var lAssignee string
|
||||
var lTags []string
|
||||
var lMention string
|
||||
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list", Short: "List nodes",
|
||||
@@ -22,7 +23,18 @@ var listCmd = &cobra.Command{
|
||||
return
|
||||
}
|
||||
svc := service.NewSQLiteNodeService(d.DB, cfg.GetUser())
|
||||
if nodes, err := svc.List(service.WithTags(lTags...), service.WithAssignee(lAssignee)); err == nil {
|
||||
opts := []service.ListOption{}
|
||||
if len(lTags) > 0 {
|
||||
opts = append(opts, service.WithTags(lTags...))
|
||||
}
|
||||
if lAssignee != "" {
|
||||
opts = append(opts, service.WithAssignee(lAssignee))
|
||||
}
|
||||
if lMention != "" {
|
||||
opts = append(opts, service.WithMentions(lMention))
|
||||
}
|
||||
|
||||
if nodes, err := svc.List(opts...); err == nil {
|
||||
output.PrintNodes(cmd.OutOrStdout(), nodes, jsonFlag)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "err: %v\n", err)
|
||||
@@ -36,4 +48,5 @@ func init() {
|
||||
f := listCmd.Flags()
|
||||
f.StringVar(&lAssignee, "assignee", "", "")
|
||||
f.StringArrayVar(&lTags, "tag", nil, "")
|
||||
f.StringVar(&lMention, "mention", "", "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user