Files
mstore/cmd/mstorectl/util/util.go
T

67 lines
1.3 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 {
// TODO: delete mixed object and use simple object?
accountcmd.AccountUtil
filecmd.FileUtil
imagecmd.ImageUtil
accountcmd.GrantUtil
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
rootCmd.AddCommand(util.MakeFileCmds())
rootCmd.AddCommand(util.MakeCollectionCmds())
rootCmd.AddCommand(util.CreateImageCmds())
rootCmd.AddCommand(util.MakeAccountCmds())
rootCmd.AddCommand(util.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!")
}