refactor(config): root cli command to read config from new package

This commit is contained in:
balanza
2026-04-02 14:49:07 +02:00
committed by Emanuele De Cupis
parent 12fd3044a9
commit 9cdbd7cf35
2 changed files with 15 additions and 14 deletions
+4 -3
View File
@@ -6,15 +6,16 @@ import (
"os"
"github.com/89luca89/distrobox/internal/cli"
"github.com/89luca89/distrobox/internal/config"
"github.com/89luca89/distrobox/pkg/config"
)
func main() {
if err := config.LoadConfig(); err != nil {
cfg, err := config.LoadValues()
if err != nil {
log.Fatal(err)
}
cmd := cli.NewRootCommand()
cmd := cli.NewRootCommand(cfg)
if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
+11 -11
View File
@@ -8,6 +8,7 @@ import (
"github.com/urfave/cli/v3"
"github.com/89luca89/distrobox/pkg/config"
"github.com/89luca89/distrobox/pkg/containermanager"
"github.com/89luca89/distrobox/pkg/containermanager/providers"
)
@@ -16,23 +17,22 @@ type contextKey string
const containerManagerKey contextKey = "containerManager"
func NewRootCommand() *cli.Command {
func NewRootCommand(cfg *config.Values) *cli.Command {
return &cli.Command{
Name: "distrobox",
Version: "1.0.0",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "container-manager",
Usage: "",
Sources: cli.EnvVars("DBX_CONTAINER_MANAGER", "container_manager"),
Hidden: true,
Name: "container-manager",
Usage: "",
Hidden: true,
Value: cfg.ContainerManagerType,
},
&cli.StringFlag{
Name: "sudo-command",
Usage: "",
Sources: cli.EnvVars("DBX_SUDO_COMMAND", "sudo_command"),
Hidden: true,
Value: "sudo",
Name: "sudo-command",
Usage: "",
Hidden: true,
Value: cfg.SudoProgram,
},
&cli.BoolFlag{
Name: "root",
@@ -45,7 +45,7 @@ func NewRootCommand() *cli.Command {
Name: "verbose",
Aliases: []string{"v"},
Usage: "show more verbosity",
Sources: cli.EnvVars("DBX_VERBOSE", "verbose"),
Value: cfg.Verbose,
},
},
Before: beforeAction,