Files
2026-06-09 14:10:53 +02:00

71 lines
1.4 KiB
Go

/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*/
package grant
import (
"mbase/pkg/client"
"github.com/spf13/cobra"
)
type CommonParams struct {
Hostname string
Port uint32
Username string
Password string
}
type Util struct {
rootCmd *cobra.Command
setGrantParams SetGrantParams
deleteGrantParams deleteGrantParams
commonParams CommonParams
access client.Access
}
func NewUtil() *Util {
return &Util{}
}
func (util *Util) GetRooCmd() *cobra.Command {
return util.rootCmd
}
func (util *Util) BuildCmds() *cobra.Command {
rootCmd := &cobra.Command{
Use: "grant",
Short: "\nGrant operations",
SilenceUsage: true,
}
rootCmd.CompletionOptions.DisableDefaultCmd = true
var setGrantCmd = &cobra.Command{
Use: "set name|id grant",
Short: "Set grant",
Args: cobra.ExactArgs(2),
Run: util.SetGrant,
}
rootCmd.AddCommand(setGrantCmd)
var deleteGrantCmd = &cobra.Command{
Use: "delete name|id grant",
Short: "Delete grant",
Args: cobra.ExactArgs(1),
Run: util.DeleteGrant,
}
rootCmd.AddCommand(deleteGrantCmd)
util.rootCmd = rootCmd
return util.rootCmd
}
func (util *Util) SetAccess(cmd *cobra.Command, args []string) {
util.access = client.Access{
Hostname: util.commonParams.Hostname,
Port: util.commonParams.Port,
Username: util.commonParams.Username,
Password: util.commonParams.Password,
}
}