-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
143 lines (128 loc) · 2.92 KB
/
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
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
136
137
138
139
140
141
142
143
package main
import (
"errors"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"time"
"github.com/briandowns/spinner"
"github.com/fatih/color"
"github.com/mitchellh/go-homedir"
"github.com/urfave/cli"
)
var (
platformHost = "https://notable.zurb.com"
version = "0.1.4"
authPath string
s = spinner.New(spinner.CharSets[6], 100*time.Millisecond)
checkNotEmpty = func(input string) error {
if input == "" {
return errors.New("Input should not be empty!")
}
return nil
}
)
func check(e error) {
if e != nil {
panic(e)
}
}
// EnvConfig is the global configuration object
type EnvConfig struct {
AuthToken string `json:"token"`
}
var envConfig = EnvConfig{}
func main() {
authRoot, err := homedir.Dir()
if err != nil {
color.Red("Cannot access your home directory to check for authentication.")
os.Exit(1)
}
authPath = fmt.Sprintf("%s/.notable_auth", authRoot)
app := cli.NewApp()
app.EnableBashCompletion = true
app.Name = "notable"
app.Usage = "Interface with Notable (http://zurb.com/notable)"
app.Version = version
app.Author = "Jordan Humphreys ([email protected])"
app.Copyright = "ZURB, Inc. 2016 (http://zurb.com)"
app.Commands = []cli.Command{
{
Name: "code",
Aliases: []string{"c"},
Usage: "Send site to Notable, local or live!",
Flags: []cli.Flag{
cli.StringFlag{
Name: "dest, d",
Value: ".",
Usage: "destination",
},
},
Action: func(c *cli.Context) error {
loadAndCheckEnv()
runCode(c)
return nil
},
},
{
Name: "notebook",
Aliases: []string{"n"},
Usage: "get design feedback on your images",
Subcommands: []cli.Command{
{
Name: "create",
Usage: "create a new notebook",
Action: func(c *cli.Context) error {
loadAndCheckEnv()
runNotebook(c)
return nil
},
},
},
},
{
Name: "login",
Aliases: []string{"l"},
Usage: "Authenticate the CLI",
Action: func(c *cli.Context) error {
runAuth(c)
return nil
},
},
{
Name: "logout",
Aliases: []string{"lo"},
Usage: "Deauthorize this computer",
Action: func(c *cli.Context) error {
removeAuth()
return nil
},
},
}
app.Run(os.Args)
}
func loadAndCheckEnv() {
config, err := readAuth()
if err != nil {
log.Fatal(err)
}
envConfig = config
}
func currentPath() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
return dir
}
func wGetCheck() {
_, err := exec.LookPath("wget")
if err != nil {
color.Red("Missing dependency!\n")
color.Red("Please install wget using Homebrew or some other fancy way:\n")
color.Green("brew up && brew install wget\n")
os.Exit(1)
}
}