From 4cabdff2565c6099deb9a72d7e3ce987382bc211 Mon Sep 17 00:00:00 2001 From: Gabriele Santomaggio <G.santomaggio@gmail.com> Date: Thu, 12 Nov 2020 14:06:09 +0100 Subject: [PATCH] Change the config (#59) make the names similar to command lines paramenters --- cmd/tools/cli/cli.go | 7 ++++--- go.mod | 2 +- internal/settings/config.go | 16 ++++++++-------- internal/settings/config_test.go | 25 +++++++++++++------------ 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/cmd/tools/cli/cli.go b/cmd/tools/cli/cli.go index e729f71..cf9533a 100644 --- a/cmd/tools/cli/cli.go +++ b/cmd/tools/cli/cli.go @@ -3,11 +3,12 @@ package cli import ( "context" "fmt" - "github.com/kf5i/k3ai-core/internal/settings" "io" "log" "os" + "github.com/kf5i/k3ai-core/internal/settings" + "github.com/kf5i/k3ai-core/internal/k8s/kctl" "github.com/spf13/cobra" ) @@ -40,8 +41,8 @@ func setupCli(baseCmd *cobra.Command) { log.Fatalf("can't read settings") } - baseCmd.PersistentFlags().StringVarP(&pluginRepoURI, "plugin-repo", "", s.PluginsURI, "URI for the plugins repository. ") - baseCmd.PersistentFlags().StringVarP(&pluginsGroupRepoURI, "group-repo", "", s.GroupsURI, "URI for the plugin groups repository") + baseCmd.PersistentFlags().StringVarP(&pluginRepoURI, "plugin-repo", "", s.PluginRepo, "URI for the plugins repository. ") + baseCmd.PersistentFlags().StringVarP(&pluginsGroupRepoURI, "group-repo", "", s.GroupRepo, "URI for the plugin groups repository") baseCmd.PersistentFlags().BoolVarP(&useKubectl, "kubectl", "", s.UseKubectl, "Use kubectl for deployment. Uses k3s when set to false") baseCmd.AddCommand(versionCmd) baseCmd.AddCommand(newApplyCommand()) diff --git a/go.mod b/go.mod index 868a314..0571679 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/Azure/go-autorest/autorest v0.11.10 // indirect github.com/golang/protobuf v1.4.3 // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/gorilla/mux v1.8.0 // indirect + github.com/gorilla/mux v1.8.0 github.com/imdario/mergo v0.3.11 // indirect github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.1.1 diff --git a/internal/settings/config.go b/internal/settings/config.go index a4d55f1..2edb435 100644 --- a/internal/settings/config.go +++ b/internal/settings/config.go @@ -14,10 +14,10 @@ import ( // Settings default user setting type Settings struct { - // PluginsURI is --plugin-repo - PluginsURI string `yaml:"plugins-url"` - // GroupsURI is --group-repo - GroupsURI string `yaml:"groups-url"` + // PluginRepo is --plugin-repo + PluginRepo string `yaml:"plugin-repo"` + // GroupRepo is --group-repo + GroupRepo string `yaml:"group-repo"` // UseKubectl use kubectl instead of k3s UseKubectl bool `yaml:"use-kubectl"` } @@ -27,8 +27,8 @@ const configFileName = "config" // GetDefaultSettings get default settings func GetDefaultSettings() *Settings { var ds Settings - ds.GroupsURI = plugins.DefaultPluginsGroupURI - ds.PluginsURI = plugins.DefaultPluginURI + ds.GroupRepo = plugins.DefaultPluginsGroupURI + ds.PluginRepo = plugins.DefaultPluginURI ds.UseKubectl = false return &ds } @@ -111,8 +111,8 @@ func loadSettingFormFile(configDir string) (*Settings, error) { return nil, err } - ds.GroupsURI = shared.GetDefaultIfEmpty(ds.GroupsURI, plugins.DefaultPluginsGroupURI) - ds.PluginsURI = shared.GetDefaultIfEmpty(ds.PluginsURI, plugins.DefaultPluginURI) + ds.GroupRepo = shared.GetDefaultIfEmpty(ds.GroupRepo, plugins.DefaultPluginsGroupURI) + ds.PluginRepo = shared.GetDefaultIfEmpty(ds.PluginRepo, plugins.DefaultPluginURI) return ds, nil } diff --git a/internal/settings/config_test.go b/internal/settings/config_test.go index edddae1..1a124a5 100644 --- a/internal/settings/config_test.go +++ b/internal/settings/config_test.go @@ -1,11 +1,12 @@ package settings import ( - "github.com/kf5i/k3ai-core/internal/plugins" - "github.com/kf5i/k3ai-core/internal/shared" "io/ioutil" "os" "testing" + + "github.com/kf5i/k3ai-core/internal/plugins" + "github.com/kf5i/k3ai-core/internal/shared" ) func TestDefaultDirDoesNotExist(t *testing.T) { @@ -16,8 +17,8 @@ func TestDefaultDirDoesNotExist(t *testing.T) { t.Fatalf("can't read setting file, error: %s", err) } - shared.AssertEqual(t, settingsToRead.GroupsURI, plugins.DefaultPluginsGroupURI, "TestDefaultDirDoesNotExist GroupsURI") - shared.AssertEqual(t, settingsToRead.PluginsURI, plugins.DefaultPluginURI, "TestDefaultDirDoesNotExist PluginsURI") + shared.AssertEqual(t, settingsToRead.GroupRepo, plugins.DefaultPluginsGroupURI, "TestDefaultDirDoesNotExist GroupsURI") + shared.AssertEqual(t, settingsToRead.PluginRepo, plugins.DefaultPluginURI, "TestDefaultDirDoesNotExist PluginsURI") shared.AssertEqual(t, settingsToRead.UseKubectl, false, "TestDefaultDirDoesNotExist K8sCli") } @@ -28,8 +29,8 @@ func TestCustomSettings(t *testing.T) { } defer os.RemoveAll(dir) var settingsToStore Settings - settingsToStore.GroupsURI = "path-groups-uri" - settingsToStore.PluginsURI = "path-plugins-uri" + settingsToStore.GroupRepo = "path-groups-uri" + settingsToStore.PluginRepo = "path-plugins-uri" settingsToStore.UseKubectl = true err = SaveSettingFile(dir, settingsToStore) @@ -42,8 +43,8 @@ func TestCustomSettings(t *testing.T) { t.Fatalf("can't read setting file, error: %s", err) } - shared.AssertEqual(t, settingsToRead.GroupsURI, settingsToStore.GroupsURI, "TestCustomSettings GroupsURI") - shared.AssertEqual(t, settingsToRead.PluginsURI, settingsToStore.PluginsURI, "TestCustomSettings PluginsURI") + shared.AssertEqual(t, settingsToRead.GroupRepo, settingsToStore.GroupRepo, "TestCustomSettings GroupsURI") + shared.AssertEqual(t, settingsToRead.PluginRepo, settingsToStore.PluginRepo, "TestCustomSettings PluginsURI") shared.AssertEqual(t, settingsToRead.UseKubectl, settingsToStore.UseKubectl, "TestCustomSettings K8sCli") } @@ -54,8 +55,8 @@ func TestCustomWithEmptySettings(t *testing.T) { } defer os.RemoveAll(dir) var settingsToStore Settings - settingsToStore.GroupsURI = "" - settingsToStore.PluginsURI = "" + settingsToStore.GroupRepo = "" + settingsToStore.PluginRepo = "" settingsToStore.UseKubectl = false err = SaveSettingFile(dir, settingsToStore) @@ -68,7 +69,7 @@ func TestCustomWithEmptySettings(t *testing.T) { t.Fatalf("can't read setting file, error: %s", err) } - shared.AssertEqual(t, settingsToRead.GroupsURI, plugins.DefaultPluginsGroupURI, "TestCustomWithEmptySettings GroupsURI") - shared.AssertEqual(t, settingsToRead.PluginsURI, plugins.DefaultPluginURI, "TestCustomWithEmptySettings PluginsURI ") + shared.AssertEqual(t, settingsToRead.GroupRepo, plugins.DefaultPluginsGroupURI, "TestCustomWithEmptySettings GroupsURI") + shared.AssertEqual(t, settingsToRead.PluginRepo, plugins.DefaultPluginURI, "TestCustomWithEmptySettings PluginsURI ") shared.AssertEqual(t, settingsToRead.UseKubectl, false, "TestCustomWithEmptySettings K8sCli") }