2023-09-07 15:20:19 +02:00
|
|
|
package settings
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2023-09-07 15:33:35 +02:00
|
|
|
"velvettear/gosync/help"
|
2023-09-07 15:20:19 +02:00
|
|
|
"velvettear/gosync/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// exported function(s)
|
|
|
|
func Initialize() {
|
|
|
|
os.Args = os.Args[1:]
|
|
|
|
var arguments []string
|
|
|
|
for index, arg := range os.Args {
|
|
|
|
switch strings.ToLower(arg) {
|
2023-09-07 15:33:35 +02:00
|
|
|
case "-h":
|
|
|
|
fallthrough
|
|
|
|
case "--help":
|
|
|
|
help.Print()
|
|
|
|
os.Exit(0)
|
2023-09-07 15:20:19 +02:00
|
|
|
case "-v":
|
|
|
|
fallthrough
|
|
|
|
case "--verbose":
|
|
|
|
setVerbose(true)
|
|
|
|
case "-c":
|
|
|
|
fallthrough
|
|
|
|
case "--concurrency":
|
|
|
|
var concurrency int
|
|
|
|
tmpIndex := index + 1
|
|
|
|
if tmpIndex < len(os.Args) {
|
|
|
|
tmp, error := strconv.Atoi(os.Args[tmpIndex])
|
|
|
|
if error == nil {
|
|
|
|
concurrency = tmp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if concurrency == 0 {
|
|
|
|
concurrency = runtime.NumCPU()
|
|
|
|
}
|
|
|
|
setConcurrency(concurrency)
|
|
|
|
case "-p":
|
|
|
|
fallthrough
|
|
|
|
case "--password":
|
|
|
|
tmpIndex := index + 1
|
|
|
|
if index > len(os.Args) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
setPassword(os.Args[tmpIndex])
|
|
|
|
case "-u":
|
|
|
|
fallthrough
|
|
|
|
case "--user":
|
|
|
|
tmpIndex := index + 1
|
|
|
|
if index > len(os.Args) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
setUser(os.Args[tmpIndex])
|
|
|
|
default:
|
|
|
|
arguments = append(arguments, arg)
|
|
|
|
}
|
|
|
|
}
|
2023-09-07 15:33:35 +02:00
|
|
|
if len(os.Args) < 2 {
|
|
|
|
log.Fatal("error: missing arguments")
|
|
|
|
}
|
2023-09-07 15:20:19 +02:00
|
|
|
setSource(arguments[0])
|
|
|
|
setTarget(arguments[1])
|
|
|
|
_, error := os.Stat(Source)
|
|
|
|
if os.IsNotExist(error) {
|
|
|
|
log.Fatal("given source does not exist", Source)
|
|
|
|
}
|
|
|
|
if !Verbose {
|
|
|
|
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
|
|
|
|
}
|