From e9f89da36fca7c332a94766e00a0a12fe63d7182 Mon Sep 17 00:00:00 2001 From: velvettear Date: Fri, 22 Sep 2023 16:28:09 +0200 Subject: [PATCH] fixed parsing of arguments --- .vscode/launch.json | 12 +++++++----- settings/arguments.go | 35 ++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8088056..ef9ea37 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,13 +8,15 @@ "mode": "auto", "program": "${workspaceFolder}/main.go", "args": [ - "/home/velvettear/downloads/music/*", - "192.168.1.11:/share/music", - "--password", - "$Velvet90", + "--verbose", + "--PASSWORD", + "$velvet90", "--concurrency", "12", - "--verbose", + "--delay", + "250", + "/home/velvettear/downloads/music/*", + "192.168.1.11:/share/tmp/music", ], "console": "integratedTerminal" }, diff --git a/settings/arguments.go b/settings/arguments.go index f290c66..fb169a4 100644 --- a/settings/arguments.go +++ b/settings/arguments.go @@ -12,17 +12,18 @@ import ( // exported function(s) func Initialize() { - os.Args = os.Args[1:] var arguments []string - for _, arg := range os.Args { - arg = strings.ToLower(arg) + for index := 1; index < len(os.Args); index++ { + arg := strings.ToLower(os.Args[index]) if arg != "-v" && arg != "--verbose" { + arguments = append(arguments, arg) continue } setVerbose(true) } - for index := 0; index < len(os.Args); index++ { - switch strings.ToLower(os.Args[index]) { + var filteredArguments []string + for index := 0; index < len(arguments); index++ { + switch arguments[index] { case "-h": fallthrough case "--help": @@ -32,8 +33,8 @@ func Initialize() { fallthrough case "--concurrency": index++ - if index < len(os.Args) { - concurrency, error := strconv.Atoi(os.Args[index]) + if index < len(arguments) { + concurrency, error := strconv.Atoi(arguments[index]) if error != nil { break } @@ -43,8 +44,8 @@ func Initialize() { fallthrough case "--delay": index++ - if index < len(os.Args) { - delay, error := strconv.Atoi(os.Args[index]) + if index < len(arguments) { + delay, error := strconv.Atoi(arguments[index]) if error != nil { break } @@ -54,27 +55,27 @@ func Initialize() { fallthrough case "--password": index++ - if index > len(os.Args) { + if index > len(arguments) { break } - setPassword(os.Args[index]) + setPassword(arguments[index]) case "-u": fallthrough case "--user": index++ - if index > len(os.Args) { + if index > len(arguments) { break } - setUser(os.Args[index]) + setUser(arguments[index]) default: - arguments = append(arguments, os.Args[index]) + filteredArguments = append(filteredArguments, arguments[index]) } } - if len(os.Args) < 2 { + if len(arguments) < 2 { log.Fatal("error: missing arguments") } - setSource(arguments[0]) - setTarget(arguments[1]) + setSource(filteredArguments[0]) + setTarget(filteredArguments[1]) if !SourceIsRemote() { source, _ := strings.CutSuffix(Source, "/*") _, error := os.Stat(source)