working commit

This commit is contained in:
2026-06-06 17:49:33 +02:00
parent c96602e933
commit 0e303ef96a
12 changed files with 89 additions and 21 deletions
+36 -1
View File
@@ -8,11 +8,17 @@ import (
"path/filepath"
"mbase/cmd/mbaseadmin/account"
"mbase/app/config"
"mbase/app/maindb"
"mbase/app/operator"
"github.com/spf13/cobra"
)
type Util struct {
lg *operator.Logic
db *maindb.Database
rootCmd *cobra.Command
}
@@ -26,6 +32,34 @@ func (util *Util) GetRooCmd() *cobra.Command {
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,
@@ -34,7 +68,7 @@ func (util *Util) Build() error {
}
rootCmd.CompletionOptions.DisableDefaultCmd = true
accountUtil := account.NewUtil()
accountUtil := account.NewUtil(util.lg)
rootCmd.AddCommand(accountUtil.BuildCmds())
util.rootCmd = rootCmd
@@ -47,3 +81,4 @@ func (util *Util) Exec(args []string) error {
err = util.rootCmd.Execute()
return err
}