From 7f2afc13cda02521545035055185440399117710 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 10 Aug 2022 15:24:12 -0400 Subject: [PATCH] cmd lint --- cmd/zrok/controller.go | 6 ++-- cmd/zrok/create.go | 79 ++++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/cmd/zrok/controller.go b/cmd/zrok/controller.go index c6381ee8..ce886902 100644 --- a/cmd/zrok/controller.go +++ b/cmd/zrok/controller.go @@ -21,11 +21,11 @@ func newControllerCommand() *controllerCommand { Aliases: []string{"ctrl"}, Args: cobra.ExactArgs(1), } - ccmd := &controllerCommand{ + command := &controllerCommand{ cmd: cmd, } - cmd.Run = ccmd.run - return ccmd + cmd.Run = command.run + return command } func (cmd *controllerCommand) run(_ *cobra.Command, args []string) { diff --git a/cmd/zrok/create.go b/cmd/zrok/create.go index ef050168..1aae78f4 100644 --- a/cmd/zrok/create.go +++ b/cmd/zrok/create.go @@ -9,7 +9,7 @@ import ( ) func init() { - createCmd.AddCommand(createAccountCmd) + createCmd.AddCommand(newCreateAccountCommand().cmd) rootCmd.AddCommand(createCmd) } @@ -18,37 +18,48 @@ var createCmd = &cobra.Command{ Short: "Create objects", } -var createAccountCmd = &cobra.Command{ - Use: "account", - Short: "create new zrok account", - Run: func(_ *cobra.Command, _ []string) { - username, err := term.Prompt("New Username: ") - if err != nil { - panic(err) - } - password, err := term.PromptPassword("New Password: ", false) - if err != nil { - panic(err) - } - confirm, err := term.PromptPassword("Confirm Password: ", false) - if err != nil { - panic(err) - } - if confirm != password { - panic("confirmed password mismatch") - } - - zrok := newZrokClient() - req := identity.NewCreateAccountParams() - req.Body = &rest_model_zrok.AccountRequest{ - Username: username, - Password: password, - } - resp, err := zrok.Identity.CreateAccount(req) - if err != nil { - panic(err) - } - - logrus.Infof("api token: %v", resp.Payload.Token) - }, +type createAccountCommand struct { + cmd *cobra.Command +} + +func newCreateAccountCommand() *createAccountCommand { + cmd := &cobra.Command{ + Use: "account", + Short: "Create new zrok account", + Args: cobra.ExactArgs(0), + } + command := &createAccountCommand{cmd: cmd} + cmd.Run = command.run + return command +} + +func (cmd *createAccountCommand) run(_ *cobra.Command, _ []string) { + username, err := term.Prompt("New Username: ") + if err != nil { + panic(err) + } + password, err := term.PromptPassword("New Password: ", false) + if err != nil { + panic(err) + } + confirm, err := term.PromptPassword("Confirm Password: ", false) + if err != nil { + panic(err) + } + if confirm != password { + panic("confirmed password mismatch") + } + + zrok := newZrokClient() + req := identity.NewCreateAccountParams() + req.Body = &rest_model_zrok.AccountRequest{ + Username: username, + Password: password, + } + resp, err := zrok.Identity.CreateAccount(req) + if err != nil { + panic(err) + } + + logrus.Infof("api token: %v", resp.Payload.Token) }