-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.go
78 lines (64 loc) · 1.54 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
package main
import (
"fmt"
"os"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/stratosnet/sds/cmd/common"
"github.com/stratosnet/sds/utils"
)
const (
RunPpd = "run-ppd"
)
func main() {
rootCmd := getRootCmd()
startCmd := getStartCmd()
rootCmd.AddCommand(startCmd)
err := rootCmd.Execute()
if err != nil {
fmt.Println(err.Error())
}
}
func getRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "sdsweb",
Short: "resource node web interface",
PersistentPreRunE: common.RootPreRunE,
}
dir, err := os.Getwd()
if err != nil {
utils.ErrorLog("failed to get working directory")
panic(err)
}
rootCmd.PersistentFlags().StringP(common.Home, "r", dir, "path for the node")
rootCmd.PersistentFlags().StringP(common.Config, "c", common.DefaultConfigPath, "configuration file path ")
return rootCmd
}
func getStartCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "start the sdsweb UI along with the node",
PreRunE: common.NodePreRunE,
RunE: startRunE,
}
cmd.Flags().Bool(RunPpd, true, "run ppd as well")
return cmd
}
func startRunE(cmd *cobra.Command, args []string) error {
err := startWebServer()
if err != nil {
return errors.New(utils.FormatError(err))
}
runPpd, err := cmd.Flags().GetBool(RunPpd)
if err != nil {
return err
}
if runPpd {
return common.NodePP(cmd, args)
}
// Run the UI server only
quit := common.GetQuitChannel()
sig := <-quit
utils.Logf("Quit signal detected: [%s]. Shutting down...", sig.String())
return nil
}