Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitops create template requires you to type too many params #2227

Closed
foot opened this issue Jan 16, 2023 · 1 comment · Fixed by #2235
Closed

gitops create template requires you to type too many params #2227

foot opened this issue Jan 16, 2023 · 1 comment · Fixed by #2235
Assignees

Comments

@foot
Copy link
Collaborator

foot commented Jan 16, 2023

e.g.

gitops create template capd-capi-template.yaml --values CLUSTER_NAME=ewq,FOO=foo,BAR=bar

We could easily use viper to read all the params from a config file instead, e.g.

gitops create template --config capd-capi-template-config.yaml

Given capd-capi-template-config.yaml

template-name: capd-capi-template.yaml
values:
  - CLUSTER_NAME=ewq
  - FOO=foo
  - BAR=bar
output-dir: ./clusters/management/clusters/
@foot
Copy link
Collaborator Author

foot commented Jan 16, 2023

Good guide to viper here with a link to example repo https://carolynvanslyck.com/blog/2020/08/sting-of-the-viper/

Also check out

func initializeConfig(cmd *cobra.Command) error {
// Set the base name of the config file, without the file extension.
viper.SetConfigName(defaultConfigFilename)
viper.AddConfigPath(".")
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
return err
}
}
// Align flag and env var names
replacer := strings.NewReplacer("-", "_")
viper.SetEnvKeyReplacer(replacer)
// Read all env var values into viper
viper.AutomaticEnv()
// Read all flag values into viper
// So they can be read from `viper.Get`, (sometimes user by weave-gitops (core))
err := viper.BindPFlags(cmd.Flags())
if err != nil {
return err
}
return nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants