73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
/*
|
|
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
|
*
|
|
* This work is published and licensed under a Creative Commons
|
|
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
|
*
|
|
* Distribution of this work is permitted, but commercial use and
|
|
* modifications are strictly prohibited.
|
|
*/
|
|
package main
|
|
|
|
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.CreateAccountCmds())
|
|
rootCmd.AddCommand(util.CreateGrantCmds())
|
|
|
|
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!")
|
|
}
|