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) CreateAccount(cmd *cobra.Command, args []string) {
|
||||
//util.createAccountParams.Filename = args[0]
|
||||
res, err := util.createAccount(util.createAccountParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type createAccountParams struct{}
|
||||
type createAccountResult struct{}
|
||||
|
||||
func (util *Util) createAccount(params createAccountParams) (createAccountResult, error) {
|
||||
var err error
|
||||
res := createAccountResult{}
|
||||
return res, err
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func (util *Util) DeleteAccount(cmd *cobra.Command, args []string) {
|
||||
//util.deleteAccountParams.Filename = args[0]
|
||||
res, err := util.deleteAccount(util.deleteAccountParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type deleteAccountParams struct{}
|
||||
type deleteAccountResult struct{}
|
||||
|
||||
func (util *Util) deleteAccount(params deleteAccountParams) (deleteAccountResult, error) {
|
||||
var err error
|
||||
res := deleteAccountResult{}
|
||||
return res, err
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func (util *Util) ListAccounts(cmd *cobra.Command, args []string) {
|
||||
//util.listAccountsParams.Filename = args[0]
|
||||
res, err := util.listAccounts(util.listAccountsParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type listAccountsParams struct{}
|
||||
type listAccountsResult struct{}
|
||||
|
||||
func (util *Util) listAccounts(params listAccountsParams) (listAccountsResult, error) {
|
||||
var err error
|
||||
res := listAccountsResult{}
|
||||
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,23 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func (util *Util) UpdateAccount(cmd *cobra.Command, args []string) {
|
||||
//util.updateAccountParams.Filename = args[0]
|
||||
res, err := util.updateAccount(util.updateAccountParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type updateAccountParams struct{}
|
||||
type updateAccountResult struct{}
|
||||
|
||||
func (util *Util) updateAccount(params updateAccountParams) (updateAccountResult, error) {
|
||||
var err error
|
||||
res := updateAccountResult{}
|
||||
return res, err
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type Util struct {
|
||||
rootCmd *cobra.Command
|
||||
createAccountParams createAccountParams
|
||||
listAccountsParams listAccountsParams
|
||||
updateAccountParams updateAccountParams
|
||||
deleteAccountParams deleteAccountParams
|
||||
}
|
||||
|
||||
func NewUtil() *Util {
|
||||
return &Util{}
|
||||
}
|
||||
|
||||
func (util *Util) GetRooCmd() *cobra.Command {
|
||||
return util.rootCmd
|
||||
}
|
||||
|
||||
func (util *Util) BuildCmds() *cobra.Command {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "account",
|
||||
Short: "\nAccount operations",
|
||||
SilenceUsage: true,
|
||||
}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
var createAccountCmd = &cobra.Command{
|
||||
Use: "create name password ",
|
||||
Short: "Create account",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: util.CreateAccount,
|
||||
}
|
||||
rootCmd.AddCommand(createAccountCmd)
|
||||
|
||||
var listAccountsCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List accounts",
|
||||
Run: util.ListAccounts,
|
||||
}
|
||||
rootCmd.AddCommand(listAccountsCmd)
|
||||
|
||||
var updateAccountsCmd = &cobra.Command{
|
||||
Use: "update name|id",
|
||||
Short: "Update account",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.UpdateAccount,
|
||||
}
|
||||
rootCmd.AddCommand(updateAccountsCmd)
|
||||
|
||||
var deleteAccountCmd = &cobra.Command{
|
||||
Use: "delete name|id",
|
||||
Short: "Delete account",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.DeleteAccount,
|
||||
}
|
||||
rootCmd.AddCommand(deleteAccountCmd)
|
||||
|
||||
util.rootCmd = rootCmd
|
||||
return util.rootCmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user