working commit
This commit is contained in:
@@ -13,27 +13,28 @@ func (util *Util) CreateAccount(cmd *cobra.Command, args []string) {
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type createAccountParams struct{
|
||||
Username string
|
||||
Password string
|
||||
type createAccountParams struct {
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
type createAccountResult struct{}
|
||||
|
||||
func (util *Util) createAccount(params createAccountParams) (createAccountResult, error) {
|
||||
var err error
|
||||
res := createAccountResult{}
|
||||
/*
|
||||
operParams := &mbctl.CreateAccountParams{
|
||||
Username: params.Username,
|
||||
Password: params.Password,
|
||||
}
|
||||
res, err = util.lg.CreateAccount(ctx, operID, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
*/
|
||||
/*
|
||||
operParams := &mbctl.CreateAccountParams{
|
||||
Username: params.Username,
|
||||
Password: params.Password,
|
||||
}
|
||||
res, err = util.lg.CreateAccount(ctx, operID, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
*/
|
||||
return res, err
|
||||
}
|
||||
|
||||
/*
|
||||
func (util *Util) CreateAccount(ctx context.Context, operID string) (*mbctl.CreateAccountResult, error) {
|
||||
var err error
|
||||
|
||||
@@ -7,15 +7,21 @@ import (
|
||||
"mbase/app/operator"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultHostname = "localhost:1025"
|
||||
)
|
||||
|
||||
type Util struct {
|
||||
oper *operator.Logic
|
||||
rootCmd *cobra.Command
|
||||
oper *operator.Logic
|
||||
subCmd *cobra.Command
|
||||
createAccountParams createAccountParams
|
||||
listAccountsParams listAccountsParams
|
||||
updateAccountParams updateAccountParams
|
||||
deleteAccountParams deleteAccountParams
|
||||
commonParams CommonParams
|
||||
}
|
||||
|
||||
func NewUtil(oper *operator.Logic) *Util {
|
||||
@@ -24,17 +30,33 @@ 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: "account",
|
||||
Short: "\nAccount 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 createAccountCmd = &cobra.Command{
|
||||
Use: "create name password ",
|
||||
@@ -42,14 +64,14 @@ func (util *Util) BuildCmds() *cobra.Command {
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: util.CreateAccount,
|
||||
}
|
||||
rootCmd.AddCommand(createAccountCmd)
|
||||
subCmd.AddCommand(createAccountCmd)
|
||||
|
||||
var listAccountsCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List accounts",
|
||||
Run: util.ListAccounts,
|
||||
}
|
||||
rootCmd.AddCommand(listAccountsCmd)
|
||||
subCmd.AddCommand(listAccountsCmd)
|
||||
|
||||
var updateAccountsCmd = &cobra.Command{
|
||||
Use: "update name|id",
|
||||
@@ -57,7 +79,7 @@ func (util *Util) BuildCmds() *cobra.Command {
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.UpdateAccount,
|
||||
}
|
||||
rootCmd.AddCommand(updateAccountsCmd)
|
||||
subCmd.AddCommand(updateAccountsCmd)
|
||||
|
||||
var deleteAccountCmd = &cobra.Command{
|
||||
Use: "delete name|id",
|
||||
@@ -65,8 +87,8 @@ func (util *Util) BuildCmds() *cobra.Command {
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.DeleteAccount,
|
||||
}
|
||||
rootCmd.AddCommand(deleteAccountCmd)
|
||||
subCmd.AddCommand(deleteAccountCmd)
|
||||
|
||||
util.rootCmd = rootCmd
|
||||
return util.rootCmd
|
||||
util.subCmd = subCmd
|
||||
return util.subCmd
|
||||
}
|
||||
|
||||
@@ -5,19 +5,20 @@ package grant
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"mbase/app/operator"
|
||||
)
|
||||
|
||||
type Util struct {
|
||||
lg *operator.Logic
|
||||
rootCmd *cobra.Command
|
||||
oper *operator.Logic
|
||||
rootCmd *cobra.Command
|
||||
createGrantParams createGrantParams
|
||||
deleteGrantParams deleteGrantParams
|
||||
}
|
||||
|
||||
func NewUtil() *Util {
|
||||
return &Util{}
|
||||
func NewUtil(oper *operator.Logic) *Util {
|
||||
return &Util{
|
||||
oper: oper,
|
||||
}
|
||||
}
|
||||
|
||||
func (util *Util) GetRooCmd() *cobra.Command {
|
||||
@@ -51,4 +52,3 @@ func (util *Util) BuildCmds() *cobra.Command {
|
||||
util.rootCmd = rootCmd
|
||||
return util.rootCmd
|
||||
}
|
||||
|
||||
|
||||
+10
-7
@@ -7,17 +7,18 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"mbase/cmd/mbaseadmin/account"
|
||||
"mbase/app/config"
|
||||
"mbase/app/maindb"
|
||||
"mbase/app/operator"
|
||||
"mbase/cmd/mbaseadmin/account"
|
||||
"mbase/cmd/mbaseadmin/grant"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type Util struct {
|
||||
lg *operator.Logic
|
||||
db *maindb.Database
|
||||
lg *operator.Logic
|
||||
db *maindb.Database
|
||||
rootCmd *cobra.Command
|
||||
}
|
||||
|
||||
@@ -32,7 +33,7 @@ func (util *Util) GetRooCmd() *cobra.Command {
|
||||
func (util *Util) Build() error {
|
||||
var err error
|
||||
|
||||
conf := config.NewConfig()
|
||||
conf := config.NewConfig()
|
||||
err = conf.ReadFile()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -67,8 +68,11 @@ func (util *Util) Build() error {
|
||||
}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
accountUtil := account.NewUtil(util.lg)
|
||||
rootCmd.AddCommand(accountUtil.BuildCmds())
|
||||
accountUtil := account.NewUtil(util.lg)
|
||||
rootCmd.AddCommand(accountUtil.BuildCmds())
|
||||
|
||||
grantUtil := grant.NewUtil(util.lg)
|
||||
rootCmd.AddCommand(grantUtil.BuildCmds())
|
||||
|
||||
util.rootCmd = rootCmd
|
||||
return err
|
||||
@@ -80,4 +84,3 @@ func (util *Util) Exec(args []string) error {
|
||||
err = util.rootCmd.Execute()
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user