-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.go
More file actions
94 lines (85 loc) · 2.3 KB
/
Copy pathcommand.go
File metadata and controls
94 lines (85 loc) · 2.3 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
package main
import (
"flag"
"fmt"
"os"
"strconv"
"strings"
)
type CmdFlags struct {
Add string
Del int
Edit string
Mark int
List bool
Help bool
Ayane bool
}
func NewCmdFlags() *CmdFlags {
cf := CmdFlags{}
flag.StringVar(&cf.Add, "add", "", "Add a new todo by specify task")
flag.StringVar(&cf.Edit, "edit", "", "Edit a tody by index & specify task")
flag.IntVar(&cf.Del, "del", -1, "Specify a todo by indec to delete")
flag.IntVar(&cf.Mark, "mark", -1, "Specify a todo by indec to check")
flag.BoolVar(&cf.List, "list", false, "List all todo")
flag.BoolVar(&cf.Help, "help", false, "All Command")
flag.BoolVar(&cf.Ayane, "ayane", false, "home page")
flag.Parse()
return &cf
}
func (cf *CmdFlags) Execute(aya *Ayane) {
switch {
case cf.List:
aya.print()
case cf.Add != "":
aya.add(cf.Add)
aya.print()
case cf.Edit != "":
part := strings.SplitN(cf.Edit, ":", 2)
if len(part) != 2 {
fmt.Println("Error: invalid format for edit.")
os.Exit(1)
}
index, err := strconv.Atoi(part[0])
if err != nil {
fmt.Println("Error: invalid index for edit")
os.Exit(1)
}
aya.edit(index, part[1])
aya.print()
case cf.Mark != -1:
aya.check(cf.Mark)
aya.print()
case cf.Del != -1:
aya.delete(cf.Del)
aya.print()
case cf.Help:
AllCommand()
HowtoUseCommand()
case cf.Ayane:
Display()
default:
fmt.Println("")
}
}
func AllCommand() {
fmt.Printf("All Command: \n")
fmt.Printf(" %-10s %s\n", "-add", "Add a new todo by specify task")
fmt.Printf(" %-10s %s\n", "-edit", "Edit a tody by index & specify task")
fmt.Printf(" %-10s %s\n", "-del", "Specify a todo by index to delete")
fmt.Printf(" %-10s %s\n", "-list", "List all todo")
fmt.Printf(" %-10s %s\n", "-mark", "Specify a todo by index to mark")
fmt.Printf(" %-10s %s\n", "-help", "All Command")
fmt.Printf(" %-10s %s\n", "-ayane", "home page")
fmt.Println()
}
func HowtoUseCommand() {
fmt.Printf("How to use command: \n")
fmt.Printf(" %-10s %s\n", "add", `-add "Your Task"`)
fmt.Printf(" %-10s %s\n", "edit", `-edit id:"Edit Task" (-edit 1:"Go Run")`)
fmt.Printf(" %-10s %s\n", "del", "-del id (-del 1)")
fmt.Printf(" %-10s %s\n", "list", "-list")
fmt.Printf(" %-10s %s\n", "mark", "-mark id (-mark 1)")
fmt.Printf(" %-10s %s\n", "help", "-help")
fmt.Printf(" %-10s %s\n", "ayane", "-ayane")
}