-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
113 lines (99 loc) · 2.16 KB
/
cli.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
package main
import (
"fmt"
"os"
"strings"
"github.com/urfave/cli"
)
var version = "dev"
type enumValue struct {
Enum []string
Default string
selected string
}
func (e *enumValue) Set(value string) error {
for _, enum := range e.Enum {
if enum == value {
e.selected = value
return nil
}
}
return fmt.Errorf("allowed values are %s", strings.Join(e.Enum, ", "))
}
func (e enumValue) String() string {
if e.selected == "" {
return e.Default
}
return e.selected
}
func validateRun(c *cli.Context) error {
apiTmpl := &tmplData{
APIProjectName: c.String("project-name"),
APIProtocol: c.String("api-type"),
APIEndpoints: c.String("api-endpoint"),
LambdaFunctionName: "helloworld",
Language: c.String("language"),
}
err := apiTmpl.bootstrapAPI()
if err != nil {
return err
}
return nil
}
func runCLI(args []string) {
app := cli.NewApp()
app.Name = "alviss"
app.HelpName = "alviss"
app.UsageText = "alviss [command] [command options] [arguments...]"
app.EnableBashCompletion = true
app.Usage = ""
app.Version = version
app.Authors = []cli.Author{
{
Name: "Roger Welin",
},
}
app.Commands = []cli.Command{
{
Name: "new-api",
Usage: "Generates a new api project",
Flags: []cli.Flag{
cli.StringFlag{
Name: "p, project-name",
Usage: "name of your API project",
Required: true,
},
cli.GenericFlag{
Name: "t, api-type",
Usage: "api type (only rest supported for now)",
Value: &enumValue{
Enum: []string{"rest"},
Default: "rest",
},
},
cli.GenericFlag{
Name: "e, api-endpoint",
Usage: "which endpoint type (either regional, edge or private)",
Value: &enumValue{
Enum: []string{"regional", "edge", "private"},
Default: "regional",
},
},
cli.GenericFlag{
Name: "l, language",
Usage: "which language for lambda to be used (go, node, python, ruby)",
Value: &enumValue{
Enum: []string{"go", "node", "python", "ruby"},
Default: "node",
},
},
},
Action: validateRun,
},
}
err := app.Run(args)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
}