From b781d56161af23c452a95b3db7d87d061b7a6072 Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Fri, 24 Oct 2014 13:10:56 +0200 Subject: [PATCH] refactor main/client args --- main/client.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/main/client.go b/main/client.go index a37da24..0d00284 100644 --- a/main/client.go +++ b/main/client.go @@ -5,6 +5,7 @@ import ( "flag" "os" "fmt" + "strings" ) func Fail(err interface{}) { @@ -14,11 +15,11 @@ func Fail(err interface{}) { fmt.Println("Usage: client FLAGS ARGS") fmt.Println("Flags:") flag.PrintDefaults() - fmt.Println("Method:") - fmt.Println(" LIST, PROPFIND:") - fmt.Println(" RM, DELETE, DEL:") - fmt.Println(" MKDIR, MKCOL:") - fmt.Println(" MKDIRALL, MKCOLALL:") + fmt.Println("Method ") + fmt.Println(" LS | LIST | PROPFIND ") + fmt.Println(" RM | DELETE | DEL ") + fmt.Println(" MKDIR | MKCOL ") + fmt.Println(" MKDIRALL | MKCOLALL ") } os.Exit(-1) } @@ -27,7 +28,8 @@ func main() { root := flag.String("root", "URL", "WebDAV Endpoint") usr := flag.String("user", "", "user") pw := flag.String("pw", "", "password") - m := flag.String("X", "GET", "Method ...") + mm := strings.ToUpper(*(flag.String("X", "GET", "Method ..."))) + m := &mm flag.Parse() if *root == "URL" { @@ -38,11 +40,11 @@ func main() { if err := c.Connect(); err != nil { Fail(fmt.Sprintf("Failed to connect due to: %s", err.Error())) } - - if len(flag.Args()) > 0 { + alen := len(flag.Args()) + if alen == 1 { path := flag.Args()[0] switch *m { - case "LIST", "PROPFIND": + case "LS", "LIST", "PROPFIND": if files, err := c.ReadDir(path); err == nil { fmt.Println(fmt.Sprintf("ReadDir: '%s' entries: %d ", path, len(files))) for _, f := range files { @@ -77,8 +79,14 @@ func main() { default: Fail(nil) } + + } else if alen == 2 { + a0 := flag.Args()[0] + a1 := flag.Args()[1] + switch *m { + default: Fail(nil) + } } else { Fail(nil) } } -