working commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func (util *Util) CreateGrant(cmd *cobra.Command, args []string) {
|
||||
//util.createGrantParams.Filename = args[0]
|
||||
res, err := util.createGrant(util.createGrantParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type createGrantParams struct{}
|
||||
type createGrantResult struct{}
|
||||
|
||||
func (util *Util) createGrant(params createGrantParams) (createGrantResult, error) {
|
||||
var err error
|
||||
res := createGrantResult{}
|
||||
return res, err
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func (util *Util) DeleteGrant(cmd *cobra.Command, args []string) {
|
||||
//util.deleteGrantParams.Filename = args[0]
|
||||
res, err := util.deleteGrant(util.deleteGrantParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type deleteGrantParams struct{}
|
||||
type deleteGrantResult struct{}
|
||||
|
||||
func (util *Util) deleteGrant(params deleteGrantParams) (deleteGrantResult, error) {
|
||||
var err error
|
||||
res := deleteGrantResult{}
|
||||
return res, err
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package account
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
func printResponse(res any, err error) {
|
||||
type Response struct {
|
||||
Error bool `json:"error" yaml:"error"`
|
||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
||||
Result any `json:"result,omitempty" yaml:"result,omitempty"`
|
||||
}
|
||||
resp := Response{}
|
||||
if err != nil {
|
||||
resp.Error = true
|
||||
resp.Message = err.Error()
|
||||
} else {
|
||||
resp.Result = res
|
||||
}
|
||||
respBytes, _ := yaml.Marshal(resp)
|
||||
fmt.Printf("---\n%s\n", string(respBytes))
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package grant
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type Util struct {
|
||||
rootCmd *cobra.Command
|
||||
createGrantParams createGrantParams
|
||||
deleteGrantParams deleteGrantParams
|
||||
}
|
||||
|
||||
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 createGrantCmd = &cobra.Command{
|
||||
Use: "create name|id password",
|
||||
Short: "Create grant",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: util.CreateGrant,
|
||||
}
|
||||
rootCmd.AddCommand(createGrantCmd)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user