This repository was archived by the owner on Mar 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
104 lines (88 loc) · 3.09 KB
/
main.go
File metadata and controls
104 lines (88 loc) · 3.09 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
package main
import (
"github.com/nickswift/birdwatch/config"
"github.com/nickswift/birdwatch/client"
"github.com/nickswift/birdwatch/cli"
"github.com/nickswift/birdwatch/cli/actions"
"github.com/nickswift/birdwatch/cli/tasks"
"fmt"
"bufio"
"os"
)
func title() {
fmt.Println(``)
fmt.Println(`+------------------------------------------------------------------------+`)
fmt.Println(`| ██████╗ ██╗██████╗ ██████╗ ██╗ ██╗ █████╗ ████████╗ ██████╗██╗ ██╗ |`)
fmt.Println(`| ██╔══██╗██║██╔══██╗██╔══██╗██║ ██║██╔══██╗╚══██╔══╝██╔════╝██║ ██║ |`)
fmt.Println(`| ██████╔╝██║██████╔╝██║ ██║██║ █╗ ██║███████║ ██║ ██║ ███████║ |`)
fmt.Println(`| ██╔══██╗██║██╔══██╗██║ ██║██║███╗██║██╔══██║ ██║ ██║ ██╔══██║ |`)
fmt.Println(`| ██████╔╝██║██║ ██║██████╔╝╚███╔███╔╝██║ ██║ ██║ ╚██████╗██║ ██║ |`)
fmt.Println(`| ╚═════╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ |`)
fmt.Println(`+------------------------------------------------------------------------+`)
fmt.Println(``)
}
func version() string {
return fmt.Sprintf("birdwatch v%d.%d", config.VERSION_MAJOR, config.VERSION_MINOR)
}
func help() string {
return ``
}
func main() {
// show title
title()
// retrieve twitter client
tc := client.TwitterClientFromEnv()
// collect user input
cliReader := bufio.NewReader(os.Stdin)
for {
// print prompt
fmt.Printf("birdwatch > ")
// catch input and do some throat clearing
cmd, _ := cliReader.ReadString('\n')
paction, _, pargs := cli.ProcessCommand(cmd)
if pargs == nil {
pargs = []string{""}
}
// catch special commands first
var specialcmd, exitcmd bool
switch paction {
case "exit":
exitcmd = true
break
case "version":
fmt.Println(version())
specialcmd = true
case "help":
fmt.Println(help())
specialcmd = true
}
// special commands take precedence
if specialcmd {
continue
}
// exit command quits
if exitcmd {
break
}
// process command
action, task, args := cli.ProcessCommand(cmd)
// catch unrecognized commands
cmdOK := true
if _, ok := actions.Actions[action]; !ok {
fmt.Println("unrecognized action")
cmdOK = false
}
if _, ok := tasks.Tasks[task]; !ok {
fmt.Println("unrecognized task")
cmdOK = false
}
if !cmdOK {
continue
}
actionfn := actions.Actions[action]
taskfn := tasks.Tasks[task]
// do action
actionfn(tc, taskfn, args...)
}
fmt.Println("Excelsior!")
}