fixed parsing of arguments
This commit is contained in:
parent
5eab61d350
commit
f67203286c
1 changed files with 11 additions and 22 deletions
|
@ -13,8 +13,9 @@ import (
|
|||
func Initialize() {
|
||||
os.Args = os.Args[1:]
|
||||
var arguments []string
|
||||
for index, arg := range os.Args {
|
||||
switch strings.ToLower(arg) {
|
||||
for index := 0; index < len(os.Args); index++ {
|
||||
// for index, arg := range os.Args {
|
||||
switch strings.ToLower(os.Args[index]) {
|
||||
case "-h":
|
||||
fallthrough
|
||||
case "--help":
|
||||
|
@ -27,10 +28,10 @@ func Initialize() {
|
|||
case "-c":
|
||||
fallthrough
|
||||
case "--concurrency":
|
||||
index++
|
||||
var concurrency int
|
||||
tmpIndex := index + 1
|
||||
if tmpIndex < len(os.Args) {
|
||||
tmp, error := strconv.Atoi(os.Args[tmpIndex])
|
||||
if index < len(os.Args) {
|
||||
tmp, error := strconv.Atoi(os.Args[index])
|
||||
if error == nil {
|
||||
concurrency = tmp
|
||||
}
|
||||
|
@ -42,21 +43,21 @@ func Initialize() {
|
|||
case "-p":
|
||||
fallthrough
|
||||
case "--password":
|
||||
tmpIndex := index + 1
|
||||
index++
|
||||
if index > len(os.Args) {
|
||||
break
|
||||
}
|
||||
setPassword(os.Args[tmpIndex])
|
||||
setPassword(os.Args[index])
|
||||
case "-u":
|
||||
fallthrough
|
||||
case "--user":
|
||||
tmpIndex := index + 1
|
||||
index++
|
||||
if index > len(os.Args) {
|
||||
break
|
||||
}
|
||||
setUser(os.Args[tmpIndex])
|
||||
setUser(os.Args[index])
|
||||
default:
|
||||
arguments = append(arguments, arg)
|
||||
arguments = append(arguments, os.Args[index])
|
||||
}
|
||||
}
|
||||
if len(os.Args) < 2 {
|
||||
|
@ -72,15 +73,3 @@ func Initialize() {
|
|||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue