diff --git a/cmd/zrok/controller.go b/cmd/zrok/controller.go index ce886902..62d1f5c4 100644 --- a/cmd/zrok/controller.go +++ b/cmd/zrok/controller.go @@ -10,8 +10,7 @@ func init() { } type controllerCommand struct { - dbPath string - cmd *cobra.Command + cmd *cobra.Command } func newControllerCommand() *controllerCommand { @@ -21,9 +20,7 @@ func newControllerCommand() *controllerCommand { Aliases: []string{"ctrl"}, Args: cobra.ExactArgs(1), } - command := &controllerCommand{ - cmd: cmd, - } + command := &controllerCommand{cmd: cmd} cmd.Run = command.run return command } diff --git a/cmd/zrok/enable.go b/cmd/zrok/enable.go index 7997b799..a35c156c 100644 --- a/cmd/zrok/enable.go +++ b/cmd/zrok/enable.go @@ -13,19 +13,27 @@ import ( ) func init() { - enableCmd.Flags().StringVarP(&enableDescription, "description", "d", "@", "Description of this environment") - rootCmd.AddCommand(enableCmd) + rootCmd.AddCommand(newEnableCommand().cmd) } -var enableCmd = &cobra.Command{ - Use: "enable ", - Short: "Enable an environment for zrok", - Args: cobra.ExactArgs(1), - Run: enable, +type enableCommand struct { + description string + cmd *cobra.Command } -var enableDescription string -func enable(_ *cobra.Command, args []string) { +func newEnableCommand() *enableCommand { + cmd := &cobra.Command{ + Use: "enable ", + Short: "Enable an environment for zrok", + Args: cobra.ExactArgs(1), + } + command := &enableCommand{cmd: cmd} + cmd.Flags().StringVarP(&command.description, "description", "d", "@", "Description of this environment") + cmd.Run = command.run + return command +} + +func (cmd *enableCommand) run(_ *cobra.Command, args []string) { token := args[0] hostName, hostDetail, err := getHost() @@ -37,15 +45,15 @@ func enable(_ *cobra.Command, args []string) { panic(err) } hostDetail = fmt.Sprintf("%v; %v", user.Username, hostDetail) - if enableDescription == "@" { - enableDescription = fmt.Sprintf("%v@%v", user.Username, hostName) + if cmd.description == "@" { + cmd.description = fmt.Sprintf("%v@%v", user.Username, hostName) } zrok := newZrokClient() auth := httptransport.APIKeyAuth("X-TOKEN", "header", token) req := identity.NewEnableParams() req.Body = &rest_model_zrok.EnableRequest{ - Description: enableDescription, + Description: cmd.description, Host: hostDetail, } resp, err := zrok.Identity.Enable(req, auth)