From 0585c58d9cfb20de20b536f4b52037b48e47b27e Mon Sep 17 00:00:00 2001 From: Lenni vH Date: Sat, 1 May 2021 11:43:49 +0200 Subject: [PATCH] named constants for overwrite mode --- .gitignore | 2 ++ flags.go | 33 ++++++++++++++++++++------------- ui.go | 2 +- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 61f58d2..583cd83 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ qwertz *.img test test2 +old.txt +new.txt # executables: a.out diff --git a/flags.go b/flags.go index 53514fa..7165cc6 100644 --- a/flags.go +++ b/flags.go @@ -27,11 +27,18 @@ const ( VerbDebug ) -// onExistingFile takes one of these values: -// 0 skip -// 1 overwrite -// 2 ask. -var onExistingFile uint8 = 2 +var onExistingFile uint8 = Ask + +const ( + // Skip existing files. + Skip uint8 = iota + + // Overwrite existing files. + Overwrite + + // Ask the user on existing files. + Ask +) // followSymlinks takes one of these values: // 0 ignore symlinks @@ -64,11 +71,11 @@ func parseKeyValue(key string, value string) { case "overwrite": switch value { case "skip": - onExistingFile = 0 + onExistingFile = Skip case "overwrite": - onExistingFile = 1 + onExistingFile = Overwrite case "ask": - onExistingFile = 2 + onExistingFile = Ask } case "symlinks": switch value { @@ -154,18 +161,18 @@ func parseFlag(prefix string, flag string) { case "colortest": printColortest() os.Exit(0) - case "f", "force": - onExistingFile = 1 + case "n", "no-clobber", "no-overwrite": + onExistingFile = Skip + case "f", "force", "overwrite": + onExistingFile = Overwrite case "i", "interactive": - onExistingFile = 2 + onExistingFile = Ask case "no-config": doReadConfig = false case "color": color.Init(true) case "reflink": doReflinks = 2 - case "n", "no-clobber": // case "no-overwrite": - onExistingFile = 0 default: errUnknownOption(prefix + flag) } diff --git a/ui.go b/ui.go index 2f4fef0..47256d0 100644 --- a/ui.go +++ b/ui.go @@ -120,7 +120,7 @@ func printColortest() { } func verbVerboseEnabled() { - fmt.Print(color.FGColors.Yellow + "Verbose mode enabled." + color.Text.Reset) + fmt.Println(color.FGColors.Yellow + "Verbose mode enabled." + color.Text.Reset) } func verbFlags() {