package settings import ( "os" "runtime" "strconv" "strings" "time" "velvettear/gosync/help" "velvettear/gosync/log" ) // exported function(s) func Initialize() { os.Args = os.Args[1:] var arguments []string for _, arg := range os.Args { arg = strings.ToLower(arg) if arg != "-v" && arg != "--verbose" { continue } setVerbose(true) } for index := 0; index < len(os.Args); index++ { switch strings.ToLower(os.Args[index]) { case "-h": fallthrough case "--help": help.Print() os.Exit(0) case "-c": fallthrough case "--concurrency": index++ if index < len(os.Args) { concurrency, error := strconv.Atoi(os.Args[index]) if error != nil { break } setConcurrency(concurrency) } case "-d": fallthrough case "--delay": index++ if index < len(os.Args) { delay, error := strconv.Atoi(os.Args[index]) if error != nil { break } setDelay(time.Duration(delay) * time.Millisecond) } case "-p": fallthrough case "--password": index++ if index > len(os.Args) { break } setPassword(os.Args[index]) case "-u": fallthrough case "--user": index++ if index > len(os.Args) { break } setUser(os.Args[index]) default: arguments = append(arguments, os.Args[index]) } } if len(os.Args) < 2 { log.Fatal("error: missing arguments") } setSource(arguments[0]) setTarget(arguments[1]) if !SourceIsRemote() { source, _ := strings.CutSuffix(Source, "/*") _, error := os.Stat(source) if os.IsNotExist(error) { log.Fatal("given source does not exist", source) } } setDefaults() } // unexported function(s) func setDefaults() { if Concurrency == 0 { setConcurrency(runtime.NumCPU()) } if Delay == 0 { setDelay(100) } }