added cli option '-h | --help'

This commit is contained in:
Daniel Sommer 2023-09-07 15:33:35 +02:00
parent a18f8b877a
commit 3539d7c384
2 changed files with 26 additions and 3 deletions

17
help/help.go Normal file
View file

@ -0,0 +1,17 @@
package help
import (
"fmt"
)
// exported function(s)
func Print() {
fmt.Println("usage:")
fmt.Println("\tgosync [source] [target] (options)")
fmt.Println("")
fmt.Println("options:")
fmt.Println("\t-u | --user:\t\tset user for ssh / rsync")
fmt.Println("\t-p | --password:\tset password for ssh / rsync")
fmt.Println("\t-c | --concurrency:\tset limit for concurrent rsync processes")
fmt.Println("\t-v | --verbose:\t\tenable verbose / debug output")
}

View file

@ -5,18 +5,21 @@ import (
"runtime"
"strconv"
"strings"
"velvettear/gosync/help"
"velvettear/gosync/log"
)
// exported function(s)
func Initialize() {
os.Args = os.Args[1:]
if len(os.Args) < 2 {
log.Fatal("error: missing arguments")
}
var arguments []string
for index, arg := range os.Args {
switch strings.ToLower(arg) {
case "-h":
fallthrough
case "--help":
help.Print()
os.Exit(0)
case "-v":
fallthrough
case "--verbose":
@ -56,6 +59,9 @@ func Initialize() {
arguments = append(arguments, arg)
}
}
if len(os.Args) < 2 {
log.Fatal("error: missing arguments")
}
setSource(arguments[0])
setTarget(arguments[1])
if Concurrency == 0 {