Skip to content

Commit 2871a73

Browse files
authored
Merge pull request #17 from xenit-eu/allow-destroy-fail
Allow config removal command to fail
2 parents 63fe849 + b912666 commit 2871a73

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

main.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,22 @@ func main() {
106106
}
107107
}
108108

109-
const SCW_INIT_COMMAND = "scw config destroy && scw init secret-key=%s access-key=%s organization-id=%s send-telemetry=false install-autocomplete=true"
109+
const SCW_DESTROY_COMMAND = "scw config destroy"
110+
const SCW_INIT_COMMAND = "scw init secret-key=%s access-key=%s organization-id=%s send-telemetry=false install-autocomplete=true"
110111

111112
func scalewayInit(apiKey *ApiKey, organizationId string) {
112113
command := fmt.Sprintf(SCW_INIT_COMMAND, apiKey.SecretKey, apiKey.AccessKey, organizationId)
114+
115+
executeCmd(SCW_DESTROY_COMMAND)
116+
err := executeCmd(command)
117+
if err != nil {
118+
fmt.Println("Command execution failed", err)
119+
} else {
120+
fmt.Println("Command executed successfully")
121+
}
122+
}
123+
124+
func executeCmd(command string) error {
113125
var cmd *exec.Cmd
114126
if runtime.GOOS == "windows" {
115127
cmd = exec.Command("cmd.exe", "/c", command)
@@ -120,9 +132,5 @@ func scalewayInit(apiKey *ApiKey, organizationId string) {
120132
cmd.Stdout = os.Stdout
121133
cmd.Stderr = os.Stderr
122134

123-
if err := cmd.Run(); err != nil {
124-
fmt.Println("Command execution failed", err)
125-
} else {
126-
fmt.Println("Command executed successfully")
127-
}
135+
return cmd.Run()
128136
}

0 commit comments

Comments
 (0)