/* * Copyright 2026 Oleg Borodin */ package main import ( "os" "path/filepath" "mbase/app/config" "mbase/app/maindb" "mbase/app/operator" "mbase/cmd/mbaseadmin/account" "mbase/cmd/mbaseadmin/grant" "github.com/spf13/cobra" ) type Util struct { lg *operator.Logic db *maindb.Database 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 conf := config.NewConfig() err = conf.ReadFile() if err != nil { return err } err = conf.ReadEnv() if err != nil { return err } db, err := maindb.NewDatabase(conf.DataDir) if err != nil { return err } err = db.OpenDatabase() if err != nil { return err } util.db = db logicConfig := &operator.LogicConfig{ Database: util.db, } util.lg, err = operator.NewLogic(logicConfig) if err != nil { return err } execName := filepath.Base(os.Args[0]) rootCmd := &cobra.Command{ Use: execName, Short: "\nAccount operations", SilenceUsage: true, } rootCmd.CompletionOptions.DisableDefaultCmd = true accountUtil := account.NewUtil(util.lg) rootCmd.AddCommand(accountUtil.BuildCmds()) grantUtil := grant.NewUtil(util.lg) rootCmd.AddCommand(grantUtil.BuildCmds()) 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 }