forked from tidbyt/pixlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.go
35 lines (29 loc) · 772 Bytes
/
serve.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
package main
import (
"github.com/spf13/cobra"
"tidbyt.dev/pixlet/server"
)
var (
host string
port int
watch bool
)
func init() {
rootCmd.AddCommand(serveCmd)
serveCmd.Flags().StringVarP(&host, "host", "i", "127.0.0.1", "Host interface for serving rendered images")
serveCmd.Flags().IntVarP(&port, "port", "p", 8080, "Port for serving rendered images")
serveCmd.Flags().BoolVarP(&watch, "watch", "w", false, "Reload scripts on change")
}
var serveCmd = &cobra.Command{
Use: "serve [script]",
Short: "Serves a starlark render script over HTTP.",
Args: cobra.ExactArgs(1),
RunE: serve,
}
func serve(cmd *cobra.Command, args []string) error {
s, err := server.NewServer(host, port, watch, args[0])
if err != nil {
return err
}
return s.Run()
}