forked from rainycape/gondola
/
main.go
112 lines (105 loc) · 2.73 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
package main
import (
"math/rand"
"path/filepath"
"time"
"gondola/log"
"github.com/rainycape/command"
)
var (
commands = []*command.Cmd{
{
Name: "dev",
Help: "Start the Gondola development server",
Func: devCommand,
Options: &devOptions{
Dir: ".",
Port: 8888,
},
},
{
Name: "new",
Help: "Create a new Gondola project",
Usage: "<dir>",
Func: newCommand,
Options: &newOptions{Template: "hello"},
},
{
Name: "profile",
Help: "Show profiling information for a remote server running a Gondola app",
Usage: "<url>",
Func: profileCommand,
Options: &profileOptions{Method: "GET"},
},
{
Name: "bake",
Help: "Converts all assets in <dir> into Go code and generates a VFS named with <name>",
Usage: "-dir=<dir> -name=<name> ... additional flags",
Options: &bakeOptions{},
Func: bakeCommand,
},
{
Name: "random-string",
Help: "Generates a random string suitable for use as the app secret",
Func: randomStringCommand,
Options: &randomStringOptions{Length: defaultRandomLength},
},
{
Name: "rm-gen",
Help: "Remove Gondola generated files (identified by *.gen.*)",
Usage: "[dir]",
Func: rmGenCommand,
},
{
Name: "make-messages",
Help: "Generate strings files from the current package (including its non-package subdirectories, like templates)",
Func: makeMessagesCommand,
Options: &makeMessagesOptions{Out: filepath.Join("_messages", "messages.pot")},
},
{
Name: "compile-messages",
Help: "Compiles all po files from the current directory and its subdirectories",
Func: compileMessagesCommand,
Options: &compileMessagesOptions{Out: "messages.go", Messages: "_messages"},
},
{
Name: "gae-dev",
Help: "Start the Gondola App Engine development server",
Func: gaeDevCommand,
Options: &gaeDevOptions{Host: "localhost", Port: 8080, AdminPort: 8000},
},
{
Name: "gae-test",
Help: "Start serving your app on localhost and run gondola/app/tester tests against it",
Func: gaeTestCommand,
Options: &gaeTestOptions{},
},
{
Name: "gae-deploy",
Help: "Deploy your application to App Engine",
Func: gaeDeployCommand,
Options: &gaeDeployOptions{},
},
}
)
type commonOptions struct {
Quiet bool `name:"q" help:"Disable verbose output"`
}
func main() {
opts := &command.Options{
Options: &commonOptions{},
Func: func(_ *command.Cmd, opts *command.Options) error {
copts := opts.Options.(*commonOptions)
if copts.Quiet {
log.SetLevel(log.LError)
} else {
log.SetLevel(log.LDebug)
}
return nil
},
}
command.Exit(command.RunOpts(nil, opts, commands))
}
func init() {
rand.Seed(time.Now().Unix())
}