Skip to content

Commit

Permalink
CLI: Config remove unused empty fields
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Emmanuel Jacquier <[email protected]>
  • Loading branch information
pierre-emmanuelJ committed Apr 3, 2024
1 parent ed306e3 commit e472e5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ defaultaccount = "account_name"
[[accounts]]
account = "account_name"
endpoint = "https://api.exoscale.com/v1"
key = "API_KEY"
name = "account_name"
secret = "API_SECRET"
Expand Down
24 changes: 18 additions & 6 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,19 @@ func saveConfig(filePath string, newAccounts *account.Config) error {

accounts[i]["name"] = acc.Name
accounts[i]["key"] = acc.Key
accounts[i]["endpoint"] = acc.Endpoint
accounts[i]["defaultZone"] = acc.DefaultZone
accounts[i]["defaultOutputFormat"] = acc.DefaultOutputFormat
accounts[i]["clientTimeout"] = acc.ClientTimeout
accounts[i]["environment"] = acc.Environment
if acc.ClientTimeout != 0 {
accounts[i]["clientTimeout"] = acc.ClientTimeout
}
if acc.DefaultOutputFormat != "" {
accounts[i]["defaultOutputFormat"] = acc.DefaultOutputFormat
}
if acc.Environment != "" {
accounts[i]["environment"] = acc.Environment
}
if acc.Endpoint != "" {
accounts[i]["endpoint"] = acc.Endpoint
}
if acc.DefaultSSHKey != "" {
accounts[i]["defaultSSHKey"] = acc.DefaultSSHKey
}
Expand All @@ -140,10 +148,14 @@ func saveConfig(filePath string, newAccounts *account.Config) error {

accounts[accountsSize+i]["name"] = acc.Name
accounts[accountsSize+i]["key"] = acc.Key
accounts[accountsSize+i]["endpoint"] = acc.Endpoint
accounts[accountsSize+i]["secret"] = acc.Secret
accounts[accountsSize+i]["defaultZone"] = acc.DefaultZone
accounts[accountsSize+i]["environment"] = acc.Environment
if acc.Environment != "" {
accounts[i]["environment"] = acc.Environment
}
if acc.Endpoint != "" {
accounts[i]["endpoint"] = acc.Endpoint
}
if acc.DefaultSSHKey != "" {
accounts[accountsSize+i]["defaultSSHKey"] = acc.DefaultSSHKey
}
Expand Down

0 comments on commit e472e5f

Please sign in to comment.