Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
107 lines (94 loc) · 3.33 KB
/
Copy pathmain.go
File metadata and controls
107 lines (94 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"fmt"
"os"
"todo_list/internal/app"
"todo_list/internal/processor"
confprocessor "todo_list/internal/processor/conf"
cmd "github.com/DoYoungDo/commander-go"
)
func main() {
todo := cmd.New(app.APP_NAME).
Version(app.APP_VERSION).
Description("QuickTodo 是一个用于快速管理本地待办事项的终端 Todo CLI。支持添加、查看、修改、完成、删除和清空待办事项,并提供本地配置管理能力。").
Arguments("[todo...]", "待办项", nil)
// add
todo.Command("add", "添加 待办项").
Arguments("<todo...>", "待办项", nil).
Options("-d, --done", "添加时完成", nil).
Action(processor.Add)
// rm
todo.Command("rm", "删除 待办项").
Arguments("<id...>", "索引序号", nil).
Action(processor.Remove)
// mod
todo.Command("mod", "修改 待办项").
Arguments("<id>", "索引序号", nil).
Arguments("[todo]", "待办内容", nil).
Options("-a, --append", "在原内容上追加,append优先于insert", nil).
Options("-i, --insert", "在原内容上头插,insert让步于append", nil).
Options("-d, --done [done]", "修改完成状态[true|false],默认true", true).
Options("-p, --priority <priority>", "设置优先级,取值0-5;完成时强制清空优先级", nil).
Action(processor.Modify)
// list
todo.Command("list", "显示 待办项").
Options("-d, --done [done]", "只显示完成或未完成的[true|false],默认true", true).
Options("-f, --filter <matchs>", "匹配内容", nil).
Options("-i, --ignoreCase", "忽略大小写", nil).
Options("-b, --begin <begin>", "开始索引", nil).
Options("-e, --end <end>", "结束索引", nil).
Action(processor.List)
// done
todo.Command("done", "完成 待办项,等价于:mod <id> -d").
Arguments("<id...>", "索引序号", nil).
Action(func(ctx *cmd.Context) {
for _, arg := range ctx.Args() {
if err := todo.Parse([]string{"mod", arg.ForceToString(), "-d"}); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
}
}
})
// clear
todo.Command("clear", "清空 待办项").
Options("-f, --force", "不弹出确认,强制清空", nil).
Action(processor.Clear)
todo.Command("mv", "移动 待办项").
Arguments("<fromId>", "索引序号", nil).
Arguments("<toId>", "目标索引", nil).
Action(processor.Move)
// conf
conf := todo.Command("conf", "配置").
Action(func(ctx *cmd.Context) {
if err := ctx.Command().Parse([]string{"list"}); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
}
})
conf.Command("set", "设置配置").
Arguments("<key>", "配置键", nil).
Arguments("<value>", "配置值", nil).
Action(confprocessor.Set)
conf.Command("del", "删除配置").
Arguments("<key...>", "配置键", nil).
Action(confprocessor.Delete)
conf.Command("list", "列出配置").
Arguments("[key...]", "配置键", nil).
Options("--history", "显示配置历史", nil).
Action(confprocessor.List)
// 根命令 action:todo xxx 等同于 todo add xxx
todo.Action(func(ctx *cmd.Context) {
argsSize := len(ctx.Args())
if argsSize == 0 {
todo.Parse([]string{"list"})
} else {
args := []string{"add"}
for _, arg := range ctx.Args() {
args = append(args, arg.ForceToString())
}
todo.Parse(args)
}
})
if err := todo.Parse(os.Args[1:]); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
}