Files
Олег Бородин a53197e432 working commit
2026-05-26 09:58:10 +02:00

59 lines
1.1 KiB
Go

/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*/
package util
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
"mbase/cmd/mbasectl/accountcmd"
)
type Util struct {
rootCmd *cobra.Command
}
func NewUtil() *Util {
return &Util{}
}
func (util *Util) GetRooCmd() *cobra.Command {
return util.rootCmd
}
func (util *Util) Build() error {
var err error
execName := filepath.Base(os.Args[0])
rootCmd := &cobra.Command{
Use: execName,
Short: "\nOperation with artefacts: files, images, service accounts and grants",
SilenceUsage: true,
}
rootCmd.CompletionOptions.DisableDefaultCmd = true
accountUtil := accountcmd.NewAccountUtil()
rootCmd.AddCommand(accountUtil.MakeAccountCmds())
grantUtil := accountcmd.NewGrantUtil()
rootCmd.AddCommand(grantUtil.MakeGrantCmds())
util.rootCmd = rootCmd
return err
}
func (util *Util) Exec(args []string) error {
var err error
util.rootCmd.SetArgs(args)
err = util.rootCmd.Execute()
return err
}
func (util *Util) Hello(cmd *cobra.Command, args []string) {
fmt.Println("hello, world!")
}