alittle splitted mstorectl code; etc

This commit is contained in:
2026-03-05 12:26:14 +02:00
parent 80d6a244cf
commit 223ae2e96e
24 changed files with 631 additions and 104 deletions
+70
View File
@@ -0,0 +1,70 @@
/*
* 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 {
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!")
}