This repository was archived by the owner on Dec 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdoctl.go
60 lines (51 loc) · 1.38 KB
/
doctl.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
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/slantview/doctl/commands"
)
const AppVersion = "0.0.10"
func init() {
commands.APIKey = os.Getenv("DIGITAL_OCEAN_API_KEY")
}
func main() {
app := cli.NewApp()
app.Name = "doctl"
app.Version = AppVersion
app.Usage = "Digital Ocean Control TooL."
app.Flags = []cli.Flag{
cli.StringFlag{Name: "api-key,k", Value: "", Usage: "API Key for DO APIv2."},
cli.StringFlag{Name: "format,f", Value: "yaml", Usage: "Format for output."},
cli.BoolFlag{Name: "debug,d", Usage: "Turn on debug output."},
}
app.Before = func(ctx *cli.Context) error {
if ctx.String("api-key") != "" {
commands.APIKey = ctx.String("api-key")
}
switch ctx.String("format") {
case "json":
commands.OutputFormat = ctx.String("format")
case "yaml":
commands.OutputFormat = ctx.String("format")
default:
fmt.Printf("Invalid output format: %s. Available output options: json, yaml.\n", ctx.String("format"))
os.Exit(64)
}
if commands.APIKey == "" {
cli.ShowAppHelp(ctx)
fmt.Println("Must provide API Key via DIGITAL_OCEAN_API_KEY environment variable or via CLI argument.")
os.Exit(1)
}
return nil
}
app.Commands = []cli.Command{
commands.ActionCommand,
commands.DomainCommand,
commands.DropletCommand,
commands.RegionCommand,
commands.SizeCommand,
commands.SSHCommand,
}
app.Run(os.Args)
}