rscp

git clone https://orangeshoelaces.net/git/rscp.git

bc0481692b1ec877318cd769e8fe95d04fbecd33

Author: Vasily Kolobkov on 06/16/2017

Committer: Vasily Kolobkov on 06/16/2017

Handle command line arguments

Stats

main.go | 42 ++++++++
1 file changed, 42 insertions(+)

Patch

diff --git a/main.go b/main.go
index da29a2c..7db5342 100644
--- a/main.go
+++ b/main.go
@@ -1,4 +1,46 @@
 package main
 
+import (
+	"flag"
+	"fmt"
+	"os"
+)
+
+var (
+	iamSource    = flag.Bool("f", false, "Run in source mode")
+	iamSink      = flag.Bool("t", false, "Run in sink mode")
+	bwLimit      = flag.Int("l", 0, "Limit the bandwidth, specified in Kbit/s")
+	iamRecursive = flag.Bool("r", false, "Copy directoires recursively following any symlinks")
+	targetDir    = flag.Bool("d", false, "Target should be a directory")
+)
+
 func main() {
+	flag.Parse()
+	var args = flag.Args()
+
+	var validMode = (*iamSource || *iamSink) && !(*iamSource && *iamSink)
+	var validArgc = (*iamSource && len(args) > 0) || (*iamSink && len(args) == 1)
+
+	if !validMode || !validArgc {
+		usage()
+	}
+
+	if *iamSource {
+		source(args)
+	} else {
+		sink(args[0])
+	}
+}
+
+func source(args []string) {
+}
+
+func sink(arg string) {
+}
+
+func usage() {
+	fmt.Fprintf(os.Stderr, "Usage: rscp -f [-r] [-l limit] file1 ...\n"+
+		"       rscp -t [-rd] [-l limit] directory\n")
+	flag.PrintDefaults()
+	os.Exit(1)
 }