-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (47 loc) · 870 Bytes
/
main.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
package main
import (
"fmt"
"log"
"os"
)
func main() {
var l = log.New(os.Stderr, "error: ", 0)
err := processCommand()
if err != nil {
l.Fatal(err)
}
}
func processCommand() error {
if len(os.Args) == 1 {
return fmt.Errorf("引数が足りません")
}
switch cmd := os.Args[1]; cmd {
case "make":
err := make(os.Args[2:])
if err != nil {
return err
}
case "debug":
err := debug(os.Args[2:])
if err != nil {
return err
}
case "submit":
err := submit(os.Args[2:])
if err != nil {
return err
}
default:
emsg := fmt.Sprintf("コマンド'%v'は存在しません\n", cmd)
emsg += summaryCommandList([]string{"make", "debug", "submit"})
return fmt.Errorf(emsg)
}
return nil
}
func summaryCommandList(list []string) string {
s := "コマンド一覧\n\n"
for _, cmd := range list {
s += cmd + "\n"
}
return s
}