-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcli.go
More file actions
104 lines (96 loc) · 2.43 KB
/
Copy pathcli.go
File metadata and controls
104 lines (96 loc) · 2.43 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 (
"context"
"fmt"
"os"
"github.com/projecteru2/core/log"
coretypes "github.com/projecteru2/core/types"
"github.com/urfave/cli/v3"
"github.com/projecteru2/cli/cmd/core"
"github.com/projecteru2/cli/cmd/image"
"github.com/projecteru2/cli/cmd/lambda"
"github.com/projecteru2/cli/cmd/network"
"github.com/projecteru2/cli/cmd/node"
"github.com/projecteru2/cli/cmd/pod"
"github.com/projecteru2/cli/cmd/status"
"github.com/projecteru2/cli/cmd/workload"
"github.com/projecteru2/cli/describe"
"github.com/projecteru2/cli/version"
)
func main() {
cli.VersionPrinter = func(_ *cli.Command) {
fmt.Print(version.String())
}
ctx := context.Background()
if err := newApp().Run(ctx, os.Args); err != nil {
log.WithFunc("main.main").Fatalf(ctx, err, "run eru-cli")
}
}
func newApp() *cli.Command {
app := &cli.Command{
Name: version.NAME,
Usage: "control eru in shell",
Version: version.VERSION,
Before: setupLog,
Commands: []*cli.Command{
core.Command(),
image.Command(),
lambda.Command(),
network.Command(),
node.Command(),
pod.Command(),
status.Command(),
workload.Command(),
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "debug",
Usage: "enable debug",
Aliases: []string{"d"},
Value: false,
},
&cli.StringFlag{
Name: "eru",
Usage: "eru core address",
Aliases: []string{"e"},
Value: "127.0.0.1:5001",
Sources: cli.EnvVars("ERU"),
},
&cli.StringFlag{
Name: "username",
Usage: "eru core username",
Aliases: []string{"u"},
Value: "",
Sources: cli.EnvVars("ERU_USERNAME"),
},
&cli.StringFlag{
Name: "password",
Usage: "eru core password",
Aliases: []string{"p"},
Value: "",
Sources: cli.EnvVars("ERU_PASSWORD"),
},
&cli.StringFlag{
Name: "output",
Usage: "output format, json / yaml",
Aliases: []string{"o"},
Value: "",
Sources: cli.EnvVars("ERU_OUTPUT_FORMAT"),
Destination: &describe.Format,
},
},
}
// v3 reads the separator setting off the command owning the flag, not off the root.
_ = app.Walk(func(cmd *cli.Command) error {
cmd.DisableSliceFlagSeparator = true
return nil
})
return app
}
func setupLog(ctx context.Context, cmd *cli.Command) (context.Context, error) {
level := "info"
if cmd.Bool("debug") {
level = "debug"
}
return ctx, log.SetupLog(ctx, &coretypes.ServerLogConfig{Level: level}, "")
}