@@ -11,14 +11,16 @@ import (
1111)
1212
1313type setupConfig struct {
14- IdentityEndpoint string `json:"endpoint"`
15- ApplicationCredentialID string `json:"applicationCredentialId"`
16- ApplicationCredentialSecret string `json:"applicationCredentialSecret"`
17- Region string `json:"region"`
18- MountDir string `json:"mountDir"`
14+ IdentityEndpoint string `json:"endpoint,omitempty "`
15+ ApplicationCredentialID string `json:"applicationCredentialId,omitempty "`
16+ ApplicationCredentialSecret string `json:"applicationCredentialSecret,omitempty "`
17+ Region string `json:"region,omitempty "`
18+ MountDir string `json:"mountDir,omitempty "`
1919}
2020
21- func createConfiguration (configPath string ) (config setupConfig , err error ) {
21+ func createConfiguration (configPath string ) error {
22+ var config setupConfig
23+
2224 credentialInstructions :=
2325 `To get an Application Credential ID you must create new Application Credentials
2426via the web console (Horizon).
@@ -31,21 +33,26 @@ Do not close the window yet.`
3133 mountDirInstructions := `Directory used for mounting cinder volumes
3234Leave blank for default`
3335
34- var overwriteFile bool = true
35-
3636 stat , err := os .Stat (configPath )
3737 if err == nil {
3838 if stat .IsDir () {
39- return setupConfig {}, fmt .Errorf ("The configuration file path already is a directory. Delete it or choose a different path to continue." )
39+ return fmt .Errorf ("The configuration file path already is a directory. Delete it or choose a different path to continue." )
4040 } else {
41+ overwriteFile := false
42+
4143 err = huh .NewForm (
4244 huh .NewGroup (
4345 huh .NewConfirm ().Title ("The config file already exists. Overwrite it?" ).Description (fmt .Sprintf ("Path: '%s'" , configPath )).Value (& overwriteFile ),
4446 ),
4547 ).Run ()
48+ if err != nil {
49+ return err
50+ }
51+ if ! overwriteFile {
52+ return fmt .Errorf ("user aborted" )
53+ }
4654 }
47- }
48- if errors .Is (err , os .ErrNotExist ) {
55+ } else if errors .Is (err , os .ErrNotExist ) {
4956 err = os .MkdirAll (path .Dir (configPath ), 0775 )
5057 }
5158
@@ -63,15 +70,10 @@ Leave blank for default`
6370 ),
6471 ).Run ()
6572 if err != nil {
66- return setupConfig {}, err
67- }
68-
69- err = writeConfigurationFile (config , configPath )
70- if err != nil {
71- return setupConfig {}, err
73+ return err
7274 }
7375
74- return config , nil
76+ return writeConfigurationFile ( config , configPath )
7577}
7678
7779func writeConfigurationFile (config setupConfig , path string ) error {
0 commit comments