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
|
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"github.com/bosssauce/ponzu/system/admin"
"github.com/bosssauce/ponzu/system/api"
"github.com/bosssauce/ponzu/system/db"
)
var usage = `
$ ponzu <option> <params>
Options
new <directory>:
Creates a new 'ponzu' in the current directory, or one supplied
as a parameter immediately following the 'new' option. Note: 'new'
depends on the program 'git' and possibly a network connection. If there is
no local repository to clone from at the local machine's $GOPATH, 'new' will
attempt to clone the 'ponzu' package from over the network.
Example:
$ ponzu new ~/Projects/my-project.dev
generate, gen, g <type>:
Generate a content type file with boilerplate code to implement
the editor.Editable interface. Must be given one (1) parameter of
the name of the type for the new content.
Example:
$ ponzu gen review
serve, s <service> <port> <tls>:
Starts the 'ponzu' HTTP server for the JSON API, Admin System, or both.
Must be given at least one (1) parameter. The segments describe
which services to start, either 'admin' (Admin System / CMS
backend) or 'api' (JSON API), and, optionally, if the server(s) should
utilize TLS encryption (served over HTTPS), which is automatically managed
using Let's Encrypt (https://letsencrypt.org)
Example:
$ ponzu serve admin|api 8080 tls
(or)
$ ponzu serve admin
(or)
$ ponzu serve api 8888
Defaults to 'admin|api 8080' (running Admin & API on port 8080, without TLS)
Note:
Admin and API cannot run on separate processes unless you use a copy of the
database, since the first process to open it recieves a lock. If you intend
to run the Admin and API on separate processes, you must call them with the
'ponzu' command independently.
`
func init() {
flag.Usage = func() {
fmt.Println(usage)
}
}
func main() {
flag.Parse()
args := flag.Args()
if len(args) < 1 {
flag.Usage()
os.Exit(0)
}
switch args[0] {
case "new":
if len(args) < 2 {
flag.PrintDefaults()
os.Exit(0)
}
err := newProjectInDir(args[1])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case "generate", "gen", "g":
if len(args) < 2 {
flag.PrintDefaults()
os.Exit(0)
}
err := generateContentType(args[1])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case "serve", "s":
db.Init()
admin.Run()
api.Run()
log.Fatal(http.ListenAndServe(":8080", nil))
case "":
flag.PrintDefaults()
default:
flag.PrintDefaults()
}
}
|