mirror of
https://github.com/openziti/zrok.git
synced 2025-06-23 19:22:19 +02:00
better ctrl command encapsulation (#23)
This commit is contained in:
parent
d6cad21f18
commit
4cd61f85ca
@ -10,31 +10,43 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(controllerCmd)
|
rootCmd.AddCommand(newControllerCommand().cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var controllerCmd = &cobra.Command{
|
type controllerCommand struct {
|
||||||
Use: "controller <configPath>",
|
dbPath string
|
||||||
Short: "Start a zrok controller",
|
cmd *cobra.Command
|
||||||
Aliases: []string{"ctrl"},
|
}
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
|
||||||
tokens := strings.Split(endpoint, ":")
|
func newControllerCommand() *controllerCommand {
|
||||||
if len(tokens) != 2 {
|
cmd := &cobra.Command{
|
||||||
panic(errors.Errorf("malformed endpoint '%v'", endpoint))
|
Use: "controller",
|
||||||
}
|
Short: "Start a zrok controller",
|
||||||
host := tokens[0]
|
Aliases: []string{"ctrl"},
|
||||||
port, err := strconv.Atoi(tokens[1])
|
}
|
||||||
if err != nil {
|
ccmd := &controllerCommand{
|
||||||
panic(err)
|
cmd: cmd,
|
||||||
}
|
}
|
||||||
if err := controller.Run(&controller.Config{
|
cmd.Run = ccmd.run
|
||||||
Host: host,
|
cmd.Flags().StringVarP(&ccmd.dbPath, "database", "d", "zrok.db", "Path to zrok controller database")
|
||||||
Port: port,
|
return ccmd
|
||||||
Store: &store.Config{
|
}
|
||||||
Path: "zrok.db",
|
|
||||||
},
|
func (cmd *controllerCommand) run(_ *cobra.Command, _ []string) {
|
||||||
}); err != nil {
|
tokens := strings.Split(endpoint, ":")
|
||||||
panic(err)
|
if len(tokens) != 2 {
|
||||||
}
|
panic(errors.Errorf("malformed endpoint '%v'", endpoint))
|
||||||
},
|
}
|
||||||
|
host := tokens[0]
|
||||||
|
port, err := strconv.Atoi(tokens[1])
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if err := controller.Run(&controller.Config{
|
||||||
|
Host: host,
|
||||||
|
Port: port,
|
||||||
|
Store: &store.Config{Path: cmd.dbPath},
|
||||||
|
}); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user