Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: spectrocloud-labs/prompts-tui
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.1.3
Choose a base ref
...
head repository: spectrocloud-labs/prompts-tui
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.2.0
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Jan 9, 2025

  1. Add remove file prompt (#11)

    Adds a prompt that can be used to ask a user whether they want a file to be removed from disk. Includes support for default value, which can be used for example to force the prompt to default to true in case of files that contains sensitive data that we think should default to being removed.
    
    Signed-off-by: Matt Welke <matt.welke@spectrocloud.com>
    mattwelke authored Jan 9, 2025
    Copy the full SHA
    0d832ef View commit details
Showing with 22 additions and 0 deletions.
  1. +22 −0 prompts/file.go
22 changes: 22 additions & 0 deletions prompts/file.go
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import (
"strings"
"time"

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

@@ -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
}