From 52dd2cef20d9e0880955d88704159f7b8d3f7224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3=20=D0=91=D0=BE=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Sat, 6 Jun 2026 18:53:34 +0200 Subject: [PATCH] working commit --- cmd/mbaseadmin/grant/util.go | 37 ++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/cmd/mbaseadmin/grant/util.go b/cmd/mbaseadmin/grant/util.go index f07328b..f06d0cb 100644 --- a/cmd/mbaseadmin/grant/util.go +++ b/cmd/mbaseadmin/grant/util.go @@ -5,14 +5,16 @@ package grant import ( "github.com/spf13/cobra" + "github.com/spf13/viper" "mbase/app/operator" ) type Util struct { oper *operator.Logic - rootCmd *cobra.Command + subCmd *cobra.Command createGrantParams createGrantParams deleteGrantParams deleteGrantParams + commonParams CommonParams } func NewUtil(oper *operator.Logic) *Util { @@ -21,17 +23,36 @@ func NewUtil(oper *operator.Logic) *Util { } } +type CommonParams struct { + Username string + Password string +} + func (util *Util) GetRooCmd() *cobra.Command { - return util.rootCmd + return util.subCmd } func (util *Util) BuildCmds() *cobra.Command { - rootCmd := &cobra.Command{ + subCmd := &cobra.Command{ Use: "grant", Short: "\nGrant operations", SilenceUsage: true, } - rootCmd.CompletionOptions.DisableDefaultCmd = true + subCmd.CompletionOptions.DisableDefaultCmd = true + + subCmd.PersistentFlags().StringVarP(&util.commonParams.Username, "user", "U", util.commonParams.Username, "Username") + subCmd.PersistentFlags().StringVarP(&util.commonParams.Password, "pass", "P", util.commonParams.Password, "Password") + subCmd.MarkFlagsRequiredTogether("user", "pass") + + vi := viper.New() + vi.SetEnvPrefix("mstore") + vi.BindEnv("user") + vi.BindEnv("pass") + util.commonParams.Username = vi.GetString("user") + util.commonParams.Password = vi.GetString("pass") + + + var createGrantCmd = &cobra.Command{ Use: "create name|id password", @@ -39,7 +60,7 @@ func (util *Util) BuildCmds() *cobra.Command { Args: cobra.ExactArgs(2), Run: util.CreateGrant, } - rootCmd.AddCommand(createGrantCmd) + subCmd.AddCommand(createGrantCmd) var deleteGrantCmd = &cobra.Command{ Use: "delete name|id grant", @@ -47,8 +68,8 @@ func (util *Util) BuildCmds() *cobra.Command { Args: cobra.ExactArgs(1), Run: util.DeleteGrant, } - rootCmd.AddCommand(deleteGrantCmd) + subCmd.AddCommand(deleteGrantCmd) - util.rootCmd = rootCmd - return util.rootCmd + util.subCmd = subCmd + return util.subCmd }