Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Change the config
Browse files Browse the repository at this point in the history
make the names similar to command lines paramenters
  • Loading branch information
Gsantomaggio committed Nov 12, 2020
1 parent 73e16ea commit 67bf00b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
7 changes: 4 additions & 3 deletions cmd/tools/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions internal/settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 13 additions & 12 deletions internal/settings/config_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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")
}

Expand All @@ -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)
Expand All @@ -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")
}

Expand All @@ -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)
Expand All @@ -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")
}

0 comments on commit 67bf00b

Please sign in to comment.