fixed parsing of arguments

This commit is contained in:
Daniel Sommer 2023-09-08 13:29:45 +02:00
parent 5eab61d350
commit f67203286c

View file

@ -13,8 +13,9 @@ import (
func Initialize() { func Initialize() {
os.Args = os.Args[1:] os.Args = os.Args[1:]
var arguments []string var arguments []string
for index, arg := range os.Args { for index := 0; index < len(os.Args); index++ {
switch strings.ToLower(arg) { // for index, arg := range os.Args {
switch strings.ToLower(os.Args[index]) {
case "-h": case "-h":
fallthrough fallthrough
case "--help": case "--help":
@ -27,10 +28,10 @@ func Initialize() {
case "-c": case "-c":
fallthrough fallthrough
case "--concurrency": case "--concurrency":
index++
var concurrency int var concurrency int
tmpIndex := index + 1 if index < len(os.Args) {
if tmpIndex < len(os.Args) { tmp, error := strconv.Atoi(os.Args[index])
tmp, error := strconv.Atoi(os.Args[tmpIndex])
if error == nil { if error == nil {
concurrency = tmp concurrency = tmp
} }
@ -42,21 +43,21 @@ func Initialize() {
case "-p": case "-p":
fallthrough fallthrough
case "--password": case "--password":
tmpIndex := index + 1 index++
if index > len(os.Args) { if index > len(os.Args) {
break break
} }
setPassword(os.Args[tmpIndex]) setPassword(os.Args[index])
case "-u": case "-u":
fallthrough fallthrough
case "--user": case "--user":
tmpIndex := index + 1 index++
if index > len(os.Args) { if index > len(os.Args) {
break break
} }
setUser(os.Args[tmpIndex]) setUser(os.Args[index])
default: default:
arguments = append(arguments, arg) arguments = append(arguments, os.Args[index])
} }
} }
if len(os.Args) < 2 { if len(os.Args) < 2 {
@ -72,15 +73,3 @@ func Initialize() {
setVerbose(false) setVerbose(false)
} }
} }
// unexported function(s)
func removeArgument(index int) {
removeArguments(index, 0, 0)
}
func removeArguments(index int, before int, after int) {
// derp := index - 1 - before
copyArgs := os.Args[0 : index-before]
copyArgs = append(copyArgs, os.Args[index+1+after:]...)
os.Args = copyArgs
}