mirror of
https://github.com/lucheng0127/virtuallan.git
synced 2026-04-22 15:57:22 +08:00
Add RunClient function, it will used by app dashboard
This commit is contained in:
@@ -1,10 +1,67 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/lucheng0127/virtuallan/pkg/client"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
type ClientOpts func(*ClientFlags)
|
||||
|
||||
type ClientFlags struct {
|
||||
target string
|
||||
user string
|
||||
passwd string
|
||||
key string
|
||||
logLevel string
|
||||
}
|
||||
|
||||
func SetClientTarget(t string) ClientOpts {
|
||||
return func(c *ClientFlags) {
|
||||
c.target = t
|
||||
}
|
||||
}
|
||||
|
||||
func SetClientUser(u string) ClientOpts {
|
||||
return func(c *ClientFlags) {
|
||||
c.user = u
|
||||
}
|
||||
}
|
||||
|
||||
func SetClientPasswd(p string) ClientOpts {
|
||||
return func(c *ClientFlags) {
|
||||
c.passwd = p
|
||||
}
|
||||
}
|
||||
|
||||
func SetClientKey(k string) ClientOpts {
|
||||
return func(c *ClientFlags) {
|
||||
c.key = k
|
||||
}
|
||||
}
|
||||
|
||||
func SetClientLogLevel(l string) ClientOpts {
|
||||
return func(c *ClientFlags) {
|
||||
c.logLevel = l
|
||||
}
|
||||
}
|
||||
|
||||
func RunClient(opts ...ClientOpts) error {
|
||||
clientFlags := new(ClientFlags)
|
||||
for _, opt := range opts {
|
||||
opt(clientFlags)
|
||||
}
|
||||
|
||||
app := &cli.App{
|
||||
Commands: []*cli.Command{
|
||||
NewClientCmd(),
|
||||
},
|
||||
}
|
||||
|
||||
return app.Run([]string{os.Args[0], "client", "-t", clientFlags.target, "-u", clientFlags.user, "-p", clientFlags.passwd, "-k", clientFlags.key, "-l", clientFlags.logLevel})
|
||||
}
|
||||
|
||||
func NewClientCmd() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "client",
|
||||
|
||||
Reference in New Issue
Block a user