mirror of https://github.com/perkeep/perkeep.git
Start of little shared camli/clientconfig library
This commit is contained in:
parent
50280032db
commit
5de1e6c163
|
@ -0,0 +1,7 @@
|
|||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=camli/clientconfig
|
||||
GOFILES=\
|
||||
clientconfig.go
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
|
@ -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 ""
|
||||
}
|
||||
|
Loading…
Reference in New Issue