fixed parsing of arguments

This commit is contained in:
Daniel Sommer 2023-09-22 16:28:09 +02:00
parent 0804fadbb5
commit e9f89da36f
2 changed files with 25 additions and 22 deletions

12
.vscode/launch.json vendored
View file

@ -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"
},

View file

@ -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)