mirror of https://github.com/knative/client.git
Fix config init for non-writable locations (#1502)
Co-authored-by: Roland Huß <roland@ro14nd.de>
This commit is contained in:
parent
3d43c13e3e
commit
c1e35893f7
|
|
@ -39,7 +39,6 @@ var bootstrapDefaults = initDefaults()
|
||||||
const configContentDefaults = `# Taken from https://github.com/knative/client/blob/main/docs/README.md#options
|
const configContentDefaults = `# Taken from https://github.com/knative/client/blob/main/docs/README.md#options
|
||||||
#
|
#
|
||||||
#plugins:
|
#plugins:
|
||||||
# path-lookup: true
|
|
||||||
# directory: ~/.config/kn/plugins
|
# directory: ~/.config/kn/plugins
|
||||||
#eventing:
|
#eventing:
|
||||||
# sink-mappings:
|
# sink-mappings:
|
||||||
|
|
@ -145,10 +144,12 @@ func BootstrapConfig() error {
|
||||||
return fmt.Errorf("cannot stat configfile %s: %w", configFile, err)
|
return fmt.Errorf("cannot stat configfile %s: %w", configFile, err)
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(filepath.Dir(viper.ConfigFileUsed()), 0775); err != nil {
|
if err := os.MkdirAll(filepath.Dir(viper.ConfigFileUsed()), 0775); err != nil {
|
||||||
return err
|
// Can't create config directory, proceed silently without reading the config
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(viper.ConfigFileUsed(), []byte(configContentDefaults), 0600); err != nil {
|
if err := os.WriteFile(viper.ConfigFileUsed(), []byte(configContentDefaults), 0600); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "WARNING: failed writing config file to %q: %s\n", configFile, err)
|
// Can't create config file, proceed silently without reading the config
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue