add flag for confirmation

only confirm if flag is passed
This commit is contained in:
Lilian Jónsdóttir 2024-06-19 21:51:56 -07:00
parent cb2e3a72e5
commit 647a16dacb

12
main.go
View file

@ -34,6 +34,7 @@ var (
o, b, a, g, p string
ung, unp string
fo, do, ih bool
askconfirm bool
workdir, ogdir cli.Path
recursive bool
termwidth int
@ -242,6 +243,14 @@ var (
Aliases: []string{"l"},
Destination: &loglvl,
},
&cli.BoolFlag{
Name: "confirm",
Usage: "ask for confirmation before executing any action",
Value: false,
Aliases: []string{"c"},
DisableDefaultText: true,
Destination: &askconfirm,
},
}
filter_flags = []cli.Flag{
@ -452,6 +461,9 @@ func confirm_trash(fs files.Files) error {
}
func confirm(prompt string) bool {
if !askconfirm {
return true
}
// TODO: handle errors better
// switch stdin into 'raw' mode
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))