added cli option '-h | --help'
This commit is contained in:
parent
a18f8b877a
commit
3539d7c384
2 changed files with 26 additions and 3 deletions
17
help/help.go
Normal file
17
help/help.go
Normal 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")
|
||||||
|
}
|
|
@ -5,18 +5,21 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"velvettear/gosync/help"
|
||||||
"velvettear/gosync/log"
|
"velvettear/gosync/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// exported function(s)
|
// exported function(s)
|
||||||
func Initialize() {
|
func Initialize() {
|
||||||
os.Args = os.Args[1:]
|
os.Args = os.Args[1:]
|
||||||
if len(os.Args) < 2 {
|
|
||||||
log.Fatal("error: missing arguments")
|
|
||||||
}
|
|
||||||
var arguments []string
|
var arguments []string
|
||||||
for index, arg := range os.Args {
|
for index, arg := range os.Args {
|
||||||
switch strings.ToLower(arg) {
|
switch strings.ToLower(arg) {
|
||||||
|
case "-h":
|
||||||
|
fallthrough
|
||||||
|
case "--help":
|
||||||
|
help.Print()
|
||||||
|
os.Exit(0)
|
||||||
case "-v":
|
case "-v":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "--verbose":
|
case "--verbose":
|
||||||
|
@ -56,6 +59,9 @@ func Initialize() {
|
||||||
arguments = append(arguments, arg)
|
arguments = append(arguments, arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
log.Fatal("error: missing arguments")
|
||||||
|
}
|
||||||
setSource(arguments[0])
|
setSource(arguments[0])
|
||||||
setTarget(arguments[1])
|
setTarget(arguments[1])
|
||||||
if Concurrency == 0 {
|
if Concurrency == 0 {
|
||||||
|
|
Loading…
Reference in a new issue