working commit
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user