-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
135 lines (129 loc) · 4 KB
/
commands.go
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"errors"
"fmt"
)
type Command string
const (
Help Command = "help"
List Command = "list"
CreateTestStore Command = "create-test-store"
Create Command = "create"
Delete Command = "delete"
Update Command = "update"
Progress Command = "progress"
ChangeStatus Command = "change-status"
Archive Command = "archive"
)
func StringToCommand(command string) (Command, error) {
switch command {
case "help", "h":
return Help, nil
case "list", "ls":
return List, nil
case "create-test-store":
return CreateTestStore, nil
case "create", "create-item":
return Create, nil
case "delete", "delete-item", "del":
return Delete, nil
case "update", "update-item":
return Update, nil
case "progress":
return Progress, nil
case "change-status":
return ChangeStatus, nil
case "archive":
return Archive, nil
default:
err := errors.New("Invalid command: " + command + ". Use 'help' to see available commands")
return "", err
}
}
type Usage struct {
aliases string
description string
flags string
requiredFlags string
optionalFlags string
additionalInfo string
}
func GetUsage(command Command) string {
var usage Usage
switch command {
case Help:
usage = Usage{
aliases: "help, h",
description: "list available commands and their usage",
requiredFlags: "",
optionalFlags: "",
additionalInfo: "you may pass in any commands as arguments to see their usage. No commands shows all commands' usage.",
}
case List:
usage = Usage{
aliases: "list, ls",
description: "list item(s) in the todo list",
requiredFlags: "",
optionalFlags: "--all, --name, --id, --include-archived",
additionalInfo: "Unless accessed by name or id, archived items will not be shown without the --include-archived flag",
}
case CreateTestStore:
usage = Usage{
aliases: "create-test-store",
description: "create a test store with 10 items",
requiredFlags: "",
optionalFlags: "",
additionalInfo: "",
}
case Create:
usage = Usage{
aliases: "create, create-item",
description: "create an item",
requiredFlags: "--name",
optionalFlags: "--description, --status",
additionalInfo: "The description may be empty. If no status is provided, the default status is 'backlog'",
}
case Delete:
usage = Usage{
aliases: "delete, delete-item, del",
description: "delete an item",
requiredFlags: "--name or --id",
optionalFlags: "",
additionalInfo: "",
}
case Update:
usage = Usage{
aliases: "update, update-item",
description: "update an item",
requiredFlags: "--name or --id",
optionalFlags: "--description, --status, --allow-empty",
additionalInfo: "If you'd like to update the name, you must provide the id. If no status is provided, the status will not be updated. If --allow-empty is provided, the name and description may be empty",
}
case Progress:
usage = Usage{
aliases: "progress",
description: "progress an item",
requiredFlags: "--name or --id",
optionalFlags: "",
additionalInfo: "Status progression: backlog -> planned -> in-progress -> in-review -> done -> archived",
}
case ChangeStatus:
usage = Usage{
aliases: "change-status",
description: "change the status of an item",
requiredFlags: "--name or --id, --status",
optionalFlags: "",
additionalInfo: "Status options: backlog, planned, in-progress, in-review, done, archived",
}
case Archive:
usage = Usage{
aliases: "archive",
description: "archive an item",
requiredFlags: "--name or --id",
optionalFlags: "",
additionalInfo: "Archived items will not show up in the list command without the --include-archived flag",
}
}
return fmt.Sprintf("Command: %s\nDescription: %s\n\tRequired Flags: %s\n\tOptional Flags: %s\n\tAdditional Info: %s\n",
usage.aliases, usage.description, usage.requiredFlags, usage.optionalFlags, usage.additionalInfo)
}