Skip to content

Commit

Permalink
Add remove file prompt
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Welke <matt.welke@spectrocloud.com>
  • Loading branch information
mattwelke committed Jan 9, 2025
1 parent 62c9044 commit 5b85781
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions prompts/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

"github.com/pterm/pterm"
"github.com/spectrocloud-labs/prompts-tui/prompts/mocks"
)

Expand Down Expand Up @@ -182,3 +183,24 @@ func FilterLines(lines []string, validate func(input string) error) ([]string, e

return out, nil
}

// RemoveFile prompts a user whether they want to remove a file. Removes the file if the user wants
// it to be removed. If no error is encountered, prints a message telling the user the result. In
// case of error, does not print any further message and returns the error to be handled by caller.
func RemoveFile(path string, defaultVal bool) error {
remove, err := ReadBool(fmt.Sprintf("Remove file %s from disk", path), defaultVal)
if err != nil {
return err
}

if remove {
if err := os.Remove(path); err != nil {
return err
}
pterm.Info.Println("File removed.")
} else {
pterm.Info.Println("File kept.")
}

return nil
}

0 comments on commit 5b85781

Please sign in to comment.