mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
merge ucind cluster configuration to the user’s uncloud config
This commit is contained in:
+18
-1
@@ -5,11 +5,14 @@ import (
|
||||
"fmt"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"strings"
|
||||
"uncloud/cmd/ucind/cluster"
|
||||
"uncloud/internal/ucind"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var configPath string
|
||||
cmd := &cobra.Command{
|
||||
Use: "ucind",
|
||||
Short: "A CLI tool for running Uncloud test clusters using Docker.",
|
||||
@@ -24,13 +27,27 @@ func main() {
|
||||
return fmt.Errorf("create Docker client: %w", err)
|
||||
}
|
||||
|
||||
p := ucind.NewProvisioner(cli)
|
||||
if strings.HasPrefix(configPath, "~/") {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return fmt.Errorf("get user home directory to resolve %q: %w", configPath, err)
|
||||
}
|
||||
configPath = strings.Replace(configPath, "~", home, 1)
|
||||
}
|
||||
configUpdater := ucind.NewConfigUpdater(configPath)
|
||||
|
||||
p := ucind.NewProvisioner(cli, configUpdater)
|
||||
// Persist the provisioner in the context so it can be used by subcommands.
|
||||
cmd.SetContext(context.WithValue(cmd.Context(), "provisioner", p))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
// TODO: allow to override using UNCLOUD_CONFIG env var.
|
||||
cmd.PersistentFlags().StringVar(&configPath, "uncloud-config", "~/.config/uncloud/config.toml",
|
||||
"path to the Uncloud configuration file.")
|
||||
_ = cmd.MarkPersistentFlagFilename("uncloud-config", "toml")
|
||||
|
||||
cmd.AddCommand(
|
||||
cluster.NewRootCommand(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user