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

fix(generate-config): print path to configuration file #1661

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/cmd/generate/build-configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ func BuildConfiguration(svcConfig *servicecontext.ServiceConfig, opts *options)
configurations.TokenURL = providerUrls.GetTokenUrl()
configurations.Name = configInstanceName

if err = WriteConfig(opts, configurations); err != nil {
var fileName string
if fileName, err = WriteConfig(opts, configurations); err != nil {
return err
}

opts.Logger.Info(icon.SuccessPrefix(), opts.localizer.MustLocalize("generate.log.info.credentialsSaved"))
opts.Logger.Info(icon.SuccessPrefix(), opts.localizer.MustLocalize("generate.log.info.credentialsSaved", localize.NewEntry("FilePath", fileName)))

return nil
}
8 changes: 4 additions & 4 deletions pkg/cmd/generate/configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ var (

// WriteConfig saves the configurations to a file
// in the specified output format
func WriteConfig(opts *options, config *configValues) error {
func WriteConfig(opts *options, config *configValues) (string, error) {

var fileBody bytes.Buffer
fileTemplate := getFileFormat(opts.configType)
err := fileTemplate.Execute(&fileBody, config)
if err != nil {
return err
return "", err
}

fileData := []byte(fileBody.String())
Expand All @@ -47,10 +47,10 @@ func WriteConfig(opts *options, config *configValues) error {
// indicating that the user should explicitly request overwriting of the file
_, err = os.Stat(opts.fileName)
if err == nil && !opts.overwrite {
return opts.localizer.MustLocalizeError("generate.error.configFileAlreadyExists", localize.NewEntry("FilePath", opts.fileName))
return "", opts.localizer.MustLocalizeError("generate.error.configFileAlreadyExists", localize.NewEntry("FilePath", opts.fileName))
}

return ioutil.WriteFile(opts.fileName, fileData, 0o600)
return opts.fileName, ioutil.WriteFile(opts.fileName, fileData, 0o600)
}

// getDefaultPath returns the default absolute path for the configuration file
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/localize/locales/en/cmd/generate_config.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ one = 'file {{.FilePath}} already exists. Use --overwrite to overwrite the file,
one='No services available to generate configurations'

[generate.log.info.credentialsSaved]
one='Configurations successfully saved'
one='Configurations successfully saved to "{{.FilePath}}"'