Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning when deleting active profile, fix bug in list profiles #365

Merged
merged 1 commit into from
Jun 3, 2024
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