From 5de1e6c1635f86086689c029200a6c9949f89b0d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 20 Dec 2010 14:54:41 -0800 Subject: [PATCH] Start of little shared camli/clientconfig library --- lib/go/clientconfig/Makefile | 7 +++++ lib/go/clientconfig/clientconfig.go | 41 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 lib/go/clientconfig/Makefile create mode 100644 lib/go/clientconfig/clientconfig.go diff --git a/lib/go/clientconfig/Makefile b/lib/go/clientconfig/Makefile new file mode 100644 index 000000000..9651f977e --- /dev/null +++ b/lib/go/clientconfig/Makefile @@ -0,0 +1,7 @@ +include $(GOROOT)/src/Make.inc + +TARG=camli/clientconfig +GOFILES=\ + clientconfig.go + +include $(GOROOT)/src/Make.pkg diff --git a/lib/go/clientconfig/clientconfig.go b/lib/go/clientconfig/clientconfig.go new file mode 100644 index 000000000..9de659807 --- /dev/null +++ b/lib/go/clientconfig/clientconfig.go @@ -0,0 +1,41 @@ +package clientconfig + +import ( + "flag" + "log" + "strings" +) + +// These override the JSON config file ~/.camlistore's "server" and +// "password" keys +var flagServer *string = flag.String("blobserver", "", "camlistore blob server") +var flagPassword *string = flag.String("password", "", "password for blob server") + +func cleanServer(server string) string { + // Remove trailing slash if provided. + if strings.HasSuffix(server, "/") { + server = server[0 : len(server)-1] + } + // Add "http://" prefix if not present: + if !strings.HasPrefix(server, "http") { + server = "http://" + server + } + return server +} + +func BlobServerOrDie() string { + if *flagServer != "" { + return cleanServer(*flagServer) + } + log.Exitf("No --blobserver parameter specified.") + return "" +} + +func PasswordOrDie() string { + if *flagPassword != "" { + return *flagPassword + } + log.Exitf("No --password parameter specified.") + return "" +} +