-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (44 loc) · 965 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
package main
import (
"log"
"os"
)
type Driver interface {
Run() error
}
//New determines the usage that user wants to use.
//there are 3 usages; command-tool purposed usage(to simply search the selected word in selected package),
//'localhost' usage (to make server-mode possible), and 'history' usage(to show all the searched history).
//if the user's request does not fit any of the usage above, it goes to newHelper(to show users
// the usage of this command tool)
func New(args []string) (Driver, error) {
var f func(item ...string) (Driver, error)
switch len(args) {
case 1:
switch args[0] {
case "localhost":
f = newServer
case "history":
f = newHistory
default:
f = newHelper
args = os.Args
}
case 2:
f = newCommandLine
default:
f = newHelper
args = os.Args
}
return f(args...)
}
func main() {
t, err := New(os.Args[1:])
if err != nil {
log.Fatal(err)
}
err = t.Run()
if err != nil {
log.Fatal(err)
}
}