Skip to content

Commit 6f603a5

Browse files
committed
Update export --file-path description and error handling
1 parent caae881 commit 6f603a5

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

docs/stackit_config_profile_export.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ stackit config profile export PROFILE_NAME [flags]
2323
### Options
2424

2525
```
26-
-f, --file-path string If set, writes the config to the given. If unset, writes the config to you current directory with the name of the profile. E.g. '--file-path ~/my-config.json', '--file-path ~/'
26+
-f, --file-path string If set, writes the config to the given file path. If unset, writes the config to you current directory with the name of the profile. E.g. '--file-path ~/my-config.json'
2727
-h, --help Help for "stackit config profile export"
2828
```
2929

internal/cmd/config/profile/export/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
6565
}
6666

6767
func configureFlags(cmd *cobra.Command) {
68-
cmd.Flags().StringP(filePathFlag, "f", "", "If set, writes the config to the given. If unset, writes the config to you current directory with the name of the profile. E.g. '--file-path ~/my-config.json', '--file-path ~/'")
68+
cmd.Flags().StringP(filePathFlag, "f", "", "If set, writes the config to the given file path. If unset, writes the config to you current directory with the name of the profile. E.g. '--file-path ~/my-config.json'")
6969
}
7070

7171
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {

internal/pkg/config/profiles.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func ImportProfile(p *print.Printer, profileName, config string, setAsActive boo
403403
func ExportProfile(p *print.Printer, profile, exportPath string) error {
404404
err := ValidateProfile(profile)
405405
if err != nil {
406-
return fmt.Errorf("validate profile: %w", err)
406+
return fmt.Errorf("validate profile name: %w", err)
407407
}
408408

409409
exists, err := ProfileExists(profile)
@@ -417,8 +417,11 @@ func ExportProfile(p *print.Printer, profile, exportPath string) error {
417417
profilePath := GetProfileFolderPath(profile)
418418
configFile := getConfigFilePath(profilePath)
419419

420-
_, err = os.Stat(exportPath)
420+
stats, err := os.Stat(exportPath)
421421
if err == nil {
422+
if stats.IsDir() {
423+
return fmt.Errorf("export path %q is a directory. Please specify a full path", exportPath)
424+
}
422425
return &errors.FileAlreadyExistsError{Filename: exportPath}
423426
}
424427

0 commit comments

Comments
 (0)