From 1a84c6b84bc93cc285215354cde57e8effea59fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Sun, 2 Jun 2024 19:41:28 +0100 Subject: [PATCH] address acceptance issues --- internal/cmd/config/profile/delete/delete.go | 8 ++++++++ internal/pkg/config/profiles.go | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/cmd/config/profile/delete/delete.go b/internal/cmd/config/profile/delete/delete.go index d468d93ed..f93a6163f 100644 --- a/internal/cmd/config/profile/delete/delete.go +++ b/internal/cmd/config/profile/delete/delete.go @@ -55,6 +55,14 @@ func NewCmd(p *print.Printer) *cobra.Command { return &errors.DeleteDefaultProfile{DefaultProfile: config.DefaultProfileName} } + activeProfile, err := config.GetProfile() + if err != nil { + return fmt.Errorf("get profile: %w", err) + } + if activeProfile == model.Profile { + p.Warn("The profile you are trying to delete is the active profile. The default profile will be set to active.\n") + } + if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete profile %q? (This cannot be undone)", model.Profile) err = p.PromptForConfirmation(prompt) diff --git a/internal/pkg/config/profiles.go b/internal/pkg/config/profiles.go index 703031d27..f05ae9a7b 100644 --- a/internal/pkg/config/profiles.go +++ b/internal/pkg/config/profiles.go @@ -256,10 +256,20 @@ func GetProfileFolderPath(profile string) string { return filepath.Join(defaultConfigFolderPath, profileRootFolder, profile) } -// ListProfiles returns a list of all profiles. +// ListProfiles returns a list of all non-default profiles. +// If there are no profiles, it returns an empty list. func ListProfiles() ([]string, error) { profiles := []string{} + // Check if the profile root folder exists + _, err := os.Stat(filepath.Join(defaultConfigFolderPath, profileRootFolder)) + if err != nil { + if os.IsNotExist(err) { + return profiles, nil + } + return nil, fmt.Errorf("get profile root folder: %w", err) + } + profileFolders, err := os.ReadDir(filepath.Join(defaultConfigFolderPath, profileRootFolder)) if err != nil { return nil, fmt.Errorf("read profile folders: %w", err)