2019-05-21 11:31:40 +08:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2019-05-27 18:01:53 +08:00
|
|
|
"github.com/go-shiori/shiori/internal/webserver"
|
|
|
|
"github.com/sirupsen/logrus"
|
2019-05-21 11:31:40 +08:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func serveCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "serve",
|
|
|
|
Short: "Serve web interface for managing bookmarks",
|
|
|
|
Long: "Run a simple annd performant web server which " +
|
|
|
|
"serves the site for managing bookmarks. If --port " +
|
|
|
|
"flag is not used, it will use port 8080 by default.",
|
2019-05-27 18:01:53 +08:00
|
|
|
Run: serveHandler,
|
2019-05-21 11:31:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Flags().IntP("port", "p", 8080, "Port that used by server")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
2019-05-27 18:01:53 +08:00
|
|
|
|
|
|
|
func serveHandler(cmd *cobra.Command, args []string) {
|
|
|
|
port, _ := cmd.Flags().GetInt("port")
|
|
|
|
|
|
|
|
err := webserver.ServeApp(DB, DataDir, port)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatalf("Server error: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|