Skip to content

Commit

Permalink
fix: delete-dbs (#125)
Browse files Browse the repository at this point in the history
closes #116

Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 authored Feb 4, 2025
1 parent 78d4db6 commit a1234cf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ func deleteDb(_ *cobra.Command, args []string) error {
var confirmation string

home, err := os.UserHomeDir()
showpath := path
if err == nil && strings.HasPrefix(path, home) {
path = filepath.Join("~", strings.TrimPrefix(path, home))
showpath = filepath.Join("~", strings.TrimPrefix(showpath, home))
}
message := fmt.Sprintf("Are you sure you want to delete '%s' and all its contents? (y/n)", warningStyle.Render(path))
message := fmt.Sprintf("Are you sure you want to delete '%s' and all its contents? (y/n)", warningStyle.Render(showpath))
message = lipgloss.NewStyle().Width(78).Render(message)
fmt.Println(message)

Expand All @@ -262,9 +263,13 @@ func deleteDb(_ *cobra.Command, args []string) error {
return err
}
if confirmation == "y" {
return os.RemoveAll(path)
if err := os.RemoveAll(path); err != nil {
return err
}
fmt.Fprintf(os.Stderr, "Deleted %q\n", showpath)
return nil
}
fmt.Fprintf(os.Stderr, "Did not delete %q\n", path)
fmt.Fprintf(os.Stderr, "Did not delete %q\n", showpath)
return nil
}

Expand Down

0 comments on commit a1234cf

Please sign in to comment.