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
|
2023-09-22 10:54:10 +02:00
|
|
|
for _, arg := range os.Args {
|
|
|
|
arg = strings.ToLower(arg)
|
|
|
|
if arg != "-v" && arg != "--verbose" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
setVerbose(true)
|
|
|
|
}
|
2023-09-08 13:29:45 +02:00
|
|
|
for index := 0; index < len(os.Args); index++ {
|
|
|
|
switch strings.ToLower(os.Args[index]) {
|
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 "-c":
|
|
|
|
fallthrough
|
|
|
|
case "--concurrency":
|
2023-09-08 13:29:45 +02:00
|
|
|
index++
|
2023-09-07 15:20:19 +02:00
|
|
|
var concurrency int
|
2023-09-08 13:29:45 +02:00
|
|
|
if index < len(os.Args) {
|
|
|
|
tmp, error := strconv.Atoi(os.Args[index])
|
2023-09-07 15:20:19 +02:00
|
|
|
if error == nil {
|
|
|
|
concurrency = tmp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if concurrency == 0 {
|
|
|
|
concurrency = runtime.NumCPU()
|
|
|
|
}
|
|
|
|
setConcurrency(concurrency)
|
|
|
|
case "-p":
|
|
|
|
fallthrough
|
|
|
|
case "--password":
|
2023-09-08 13:29:45 +02:00
|
|
|
index++
|
2023-09-07 15:20:19 +02:00
|
|
|
if index > len(os.Args) {
|
|
|
|
break
|
|
|
|
}
|
2023-09-08 13:29:45 +02:00
|
|
|
setPassword(os.Args[index])
|
2023-09-07 15:20:19 +02:00
|
|
|
case "-u":
|
|
|
|
fallthrough
|
|
|
|
case "--user":
|
2023-09-08 13:29:45 +02:00
|
|
|
index++
|
2023-09-07 15:20:19 +02:00
|
|
|
if index > len(os.Args) {
|
|
|
|
break
|
|
|
|
}
|
2023-09-08 13:29:45 +02:00
|
|
|
setUser(os.Args[index])
|
2023-09-07 15:20:19 +02:00
|
|
|
default:
|
2023-09-08 13:29:45 +02:00
|
|
|
arguments = append(arguments, os.Args[index])
|
2023-09-07 15:20:19 +02:00
|
|
|
}
|
|
|
|
}
|
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])
|
2023-09-22 10:54:10 +02:00
|
|
|
if !SourceIsRemote() {
|
|
|
|
source, _ := strings.CutSuffix(Source, "/*")
|
|
|
|
_, error := os.Stat(source)
|
|
|
|
if os.IsNotExist(error) {
|
|
|
|
log.Fatal("given source does not exist", source)
|
|
|
|
}
|
2023-09-07 15:20:19 +02:00
|
|
|
}
|
|
|
|
}
|