79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
|
package prompts
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"os"
|
||
|
"strings"
|
||
|
"velvettear/dedupe/files"
|
||
|
"velvettear/dedupe/log"
|
||
|
"velvettear/dedupe/settings"
|
||
|
)
|
||
|
|
||
|
func ListDuplicates() {
|
||
|
log.Info("would you like to list all duplicate files? [y]es | [n]o")
|
||
|
reader := bufio.NewReader(os.Stdin)
|
||
|
input, error := reader.ReadString('\n')
|
||
|
if error != nil {
|
||
|
log.Fatal("encountered an error reading the input", error.Error())
|
||
|
}
|
||
|
input = strings.ToLower(strings.TrimSpace(strings.TrimSuffix(input, "\n")))
|
||
|
if input != "y" && input != "yes" {
|
||
|
return
|
||
|
}
|
||
|
for _, duplicate := range files.Duplicates {
|
||
|
log.Info(duplicate)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func HandleDuplicates(delete bool) bool {
|
||
|
var msg string
|
||
|
if delete {
|
||
|
msg = "are you sure you want to delete all duplicate files? [y]es | [n]o"
|
||
|
} else {
|
||
|
msg = "are you sure you want to move all duplicate files to '" + settings.MoveDirectory + "'? [y]es | [no]"
|
||
|
}
|
||
|
log.Info(msg)
|
||
|
reader := bufio.NewReader(os.Stdin)
|
||
|
input, error := reader.ReadString('\n')
|
||
|
if error != nil {
|
||
|
log.Fatal("encountered an error reading the input", error.Error())
|
||
|
}
|
||
|
input = strings.ToLower(strings.TrimSpace(strings.TrimSuffix(input, "\n")))
|
||
|
return input == "y" || input == "yes"
|
||
|
}
|
||
|
|
||
|
func DeleteOrMove() (confirmed bool, delete bool) {
|
||
|
log.Warning("parameters for both actions 'delete' and 'move' are set")
|
||
|
log.Info("do you want to delete or move all duplicate files? [d]elete | [m]ove")
|
||
|
reader := bufio.NewReader(os.Stdin)
|
||
|
input, error := reader.ReadString('\n')
|
||
|
if error != nil {
|
||
|
log.Fatal("encountered an error reading the input", error.Error())
|
||
|
}
|
||
|
input = strings.ToLower(strings.TrimSpace(strings.TrimSuffix(input, "\n")))
|
||
|
switch input {
|
||
|
case "d":
|
||
|
fallthrough
|
||
|
case "delete":
|
||
|
return HandleDuplicates(true), true
|
||
|
case "m":
|
||
|
fallthrough
|
||
|
case "move":
|
||
|
return HandleDuplicates(false), false
|
||
|
default:
|
||
|
log.Fatal("input not recognized")
|
||
|
}
|
||
|
return false, false
|
||
|
}
|
||
|
|
||
|
func DeleteEmptyDirectories(directory string) bool {
|
||
|
log.Info("do you want to delete all empty subdirectories in '" + directory + "'? [y]es | [n]o")
|
||
|
reader := bufio.NewReader(os.Stdin)
|
||
|
input, error := reader.ReadString('\n')
|
||
|
if error != nil {
|
||
|
log.Fatal("encountered an error reading the input", error.Error())
|
||
|
}
|
||
|
input = strings.ToLower(strings.TrimSpace(strings.TrimSuffix(input, "\n")))
|
||
|
return input == "y" || input == "yes"
|
||
|
}
|