Files
2026-03-26 21:08:25 +02:00

68 lines
1.4 KiB
Go

/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*/
package util
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
"mstore/cmd/mstorectl/accountcmd"
"mstore/cmd/mstorectl/filecmd"
"mstore/cmd/mstorectl/imagecmd"
)
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
fileUtil := filecmd.NewFileUtil()
rootCmd.AddCommand(fileUtil.MakeFileCmds())
rootCmd.AddCommand(fileUtil.MakeCollectionCmds())
imageUtil := imagecmd.NewImageUtil()
rootCmd.AddCommand(imageUtil.CreateImageCmds())
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!")
}