add flag for confirmation
only confirm if flag is passed
This commit is contained in:
parent
cb2e3a72e5
commit
647a16dacb
12
main.go
12
main.go
|
@ -34,6 +34,7 @@ var (
|
||||||
o, b, a, g, p string
|
o, b, a, g, p string
|
||||||
ung, unp string
|
ung, unp string
|
||||||
fo, do, ih bool
|
fo, do, ih bool
|
||||||
|
askconfirm bool
|
||||||
workdir, ogdir cli.Path
|
workdir, ogdir cli.Path
|
||||||
recursive bool
|
recursive bool
|
||||||
termwidth int
|
termwidth int
|
||||||
|
@ -242,6 +243,14 @@ var (
|
||||||
Aliases: []string{"l"},
|
Aliases: []string{"l"},
|
||||||
Destination: &loglvl,
|
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{
|
filter_flags = []cli.Flag{
|
||||||
|
@ -452,6 +461,9 @@ func confirm_trash(fs files.Files) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func confirm(prompt string) bool {
|
func confirm(prompt string) bool {
|
||||||
|
if !askconfirm {
|
||||||
|
return true
|
||||||
|
}
|
||||||
// TODO: handle errors better
|
// TODO: handle errors better
|
||||||
// switch stdin into 'raw' mode
|
// switch stdin into 'raw' mode
|
||||||
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
|
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
|
||||||
|
|
Loading…
Reference in a new issue