summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-05-29 11:43:40 -0700
committerSteve Manuel <nilslice@gmail.com>2017-05-29 11:43:40 -0700
commit0c395e5df3f82037fbdc6076df87d81ea5921574 (patch)
tree4a59f17b554514c558fcfd57ecb7ca7728556675
parentabf2c7e97b45ca9c90f0f3b3d1b6272d3ee4370b (diff)
adding --docs and --docs-port flags to config and run local docs server
-rw-r--r--cmd/ponzu/main.go33
-rw-r--r--system/admin/server.go21
2 files changed, 47 insertions, 7 deletions
diff --git a/cmd/ponzu/main.go b/cmd/ponzu/main.go
index 7572dcc..25e1694 100644
--- a/cmd/ponzu/main.go
+++ b/cmd/ponzu/main.go
@@ -26,17 +26,20 @@ import (
)
var (
- port int
httpsport int
+ port int
+ docsport int
https bool
devhttps bool
+ docs bool
cli bool
// for ponzu internal / core development
- dev bool
- fork string
gocmd string
- year = fmt.Sprintf("%d", time.Now().Year())
+ fork string
+ dev bool
+
+ year = fmt.Sprintf("%d", time.Now().Year())
)
var rootCmd = &cobra.Command{
@@ -55,7 +58,7 @@ The segments, separated by a comma, describe which services to start, either
if the server should utilize TLS encryption - served over HTTPS, which is
automatically managed using Let's Encrypt (https://letsencrypt.org)
-Defaults to 'run -port=8080 admin,api' (running Admin & API on port 8080, without TLS)
+Defaults to 'run --port=8080 admin,api' (running Admin & API on port 8080, without TLS)
Note:
Admin and API cannot run on separate processes unless you use a copy of the
@@ -81,6 +84,13 @@ $ ponzu run --port=8888 api`,
addTLS = "--dev-https"
}
+ var addDocs string
+ if docs {
+ addDocs = "--docs"
+ } else {
+ addDocs = "--docs=false"
+ }
+
var services string
if len(args) > 0 {
services = args[0]
@@ -95,6 +105,8 @@ $ ponzu run --port=8888 api`,
services,
fmt.Sprintf("--port=%d", port),
fmt.Sprintf("--https-port=%d", httpsport),
+ fmt.Sprintf("--docs-port=%d", docsport),
+ addDocs,
addTLS,
)
serve.Stderr = os.Stderr
@@ -137,6 +149,11 @@ var serveCmd = &cobra.Command{
}
}
+ // run docs server if --docs is true
+ if docs {
+ admin.Docs(docsport)
+ }
+
// save the https port the system is listening on
err := db.PutConfig("https_port", fmt.Sprintf("%d", httpsport))
if err != nil {
@@ -176,14 +193,16 @@ var serveCmd = &cobra.Command{
func init() {
for _, cmd := range []*cobra.Command{runCmd, serveCmd} {
- cmd.Flags().IntVar(&port, "port", 8080, "port for ponzu to bind its HTTP listener")
cmd.Flags().IntVar(&httpsport, "https-port", 443, "port for ponzu to bind its HTTPS listener")
+ cmd.Flags().IntVar(&port, "port", 8080, "port for ponzu to bind its HTTP listener")
+ cmd.Flags().IntVar(&docsport, "docs-port", 1234, "[dev environment] override the documentation server port")
+ cmd.Flags().BoolVar(&docs, "docs", false, "[dev environment] run HTTP server to view local HTML documentation")
cmd.Flags().BoolVar(&https, "https", false, "enable automatic TLS/SSL certificate management")
cmd.Flags().BoolVar(&devhttps, "dev-https", false, "[dev environment] enable automatic TLS/SSL certificate management")
}
- RegisterCmdlineCommand(runCmd)
RegisterCmdlineCommand(serveCmd)
+ RegisterCmdlineCommand(runCmd)
pflags := rootCmd.PersistentFlags()
pflags.StringVar(&gocmd, "gocmd", "go", "custom go command if using beta or new release of Go")
diff --git a/system/admin/server.go b/system/admin/server.go
index 426dabd..9f28a0d 100644
--- a/system/admin/server.go
+++ b/system/admin/server.go
@@ -1,6 +1,7 @@
package admin
import (
+ "fmt"
"log"
"net/http"
"os"
@@ -62,3 +63,23 @@ func Run() {
// Database & uploads backup via HTTP route registered with Basic Auth middleware.
http.HandleFunc("/admin/backup", system.BasicAuth(backupHandler))
}
+
+// Docs adds the documentation file server to the server, accessible at
+// http://localhost:1234 by default
+func Docs(port int) {
+ pwd, err := os.Getwd()
+ if err != nil {
+ log.Fatalln("Couldn't find current directory for file server.")
+ }
+
+ docsDir := filepath.Join(pwd, "docs", "build")
+
+ addr := fmt.Sprintf(":%d", port)
+ url := fmt.Sprintf("http://localhost%s", addr)
+
+ fmt.Println("")
+ fmt.Println("View documentation offline at:", url)
+ fmt.Println("")
+
+ go http.ListenAndServe(addr, http.FileServer(http.Dir(docsDir)))
+}