-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
104 lines (97 loc) · 2.56 KB
/
main.go
File metadata and controls
104 lines (97 loc) · 2.56 KB
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
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
apigateway "github.com/threefoldtech/zos4/cmds/modules/api_gateway"
"github.com/threefoldtech/zos4/cmds/modules/contd"
"github.com/threefoldtech/zos4/cmds/modules/flistd"
"github.com/threefoldtech/zos4/cmds/modules/gateway"
"github.com/threefoldtech/zos4/cmds/modules/myceliumrx"
"github.com/threefoldtech/zos4/cmds/modules/netlightd"
"github.com/threefoldtech/zos4/cmds/modules/noded"
"github.com/threefoldtech/zos4/cmds/modules/powerd"
"github.com/threefoldtech/zos4/cmds/modules/provisiond"
"github.com/threefoldtech/zos4/cmds/modules/storaged"
"github.com/threefoldtech/zos4/cmds/modules/vmd"
"github.com/threefoldtech/zos4/cmds/modules/zbusdebug"
"github.com/threefoldtech/zos4/cmds/modules/zui"
"github.com/threefoldtech/zosbase/pkg/app"
"github.com/threefoldtech/zosbase/pkg/version"
"github.com/urfave/cli/v2"
)
func main() {
app.Initialize()
exe := cli.App{
Name: "ZOS",
Version: version.Current().String(),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "list",
Hidden: true,
Usage: "print all available clients names",
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "force debug level",
},
},
Commands: []*cli.Command{
&zui.Module,
&storaged.Module,
&flistd.Module,
&contd.Module,
&vmd.Module,
&noded.Module,
&netlightd.Module,
&provisiond.Module,
&zbusdebug.Module,
&gateway.Module,
&powerd.Module,
&apigateway.Module,
&myceliumrx.Module,
},
Before: func(c *cli.Context) error {
if c.Bool("debug") {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
log.Debug().Msg("setting log level to debug")
}
return nil
},
Action: func(c *cli.Context) error {
if !c.Bool("list") {
cli.ShowAppHelpAndExit(c, 0)
}
// this hidden flag (complete) is used to list
// all available modules names to automate building of
// symlinks
for _, cmd := range c.App.VisibleCommands() {
if cmd.Name == "help" {
continue
}
fmt.Println(cmd.Name)
}
return nil
},
}
cli.VersionPrinter = func(c *cli.Context) {
fmt.Println(c.App.Version)
}
name := filepath.Base(os.Args[0])
args := os.Args
for _, cmd := range exe.Commands {
if cmd.Name == name {
args = make([]string, 0, len(os.Args)+1)
// this converts /bin/name <args> to 'zos <name> <args>
args = append(args, "bin", name)
args = append(args, os.Args[1:]...)
break
}
}
if err := exe.Run(args); err != nil {
log.Fatal().Err(err).Msg("exiting")
}
}