Skip to content
Merged
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
9 changes: 8 additions & 1 deletion internal/pkg/config/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"regexp"

"github.com/spf13/viper"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/fileutils"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
Expand Down Expand Up @@ -434,7 +435,13 @@ func ExportProfile(p *print.Printer, profile, exportPath string) error {
return &errors.FileAlreadyExistsError{Filename: exportPath}
}

err = fileutils.CopyFile(configFile, exportPath)
_, err = os.Stat(configFile)
if os.IsNotExist(err) {
// viper.SafeWriteConfigAs would not overwrite the target, so we use WriteConfigAs for the same behavior as CopyFile
err = viper.WriteConfigAs(exportPath)
} else {
err = fileutils.CopyFile(configFile, exportPath)
}
if err != nil {
return fmt.Errorf("export config file to %q: %w", exportPath, err)
}
Expand Down
Loading