Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions internal/cmd/config/profile/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion internal/pkg/config/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down