Start of little shared camli/clientconfig library

This commit is contained in:
Brad Fitzpatrick 2010-12-20 14:54:41 -08:00
parent 50280032db
commit 5de1e6c163
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,7 @@
include $(GOROOT)/src/Make.inc
TARG=camli/clientconfig
GOFILES=\
clientconfig.go
include $(GOROOT)/src/Make.pkg

View File

@ -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 ""
}