diff --git a/clients/go/camget/camget.go b/clients/go/camget/camget.go index ec26db45e..82a4f8996 100644 --- a/clients/go/camget/camget.go +++ b/clients/go/camget/camget.go @@ -31,22 +31,25 @@ limitations under the License. package main import ( - "camli/blobref" - "camli/client" "flag" "io" "log" "os" "strings" + + "camli/blobref" + "camli/client" ) -var flagVerbose *bool = flag.Bool("verbose", false, "be verbose") - -var flagCheck *bool = flag.Bool("check", false, "just check for the existence of listed blobs; returning 0 if all our present") -var flagOutput *string = flag.String("o", "-", "Output file/directory to create. Use -f to overwrite.") -var flagVia *string = flag.String("via", "", "Fetch the blob via the given comma-separated sharerefs (dev only).") +var ( + flagVerbose = flag.Bool("verbose", false, "be verbose") + flagCheck = flag.Bool("check", false, "just check for the existence of listed blobs; returning 0 if all our present") + flagOutput = flag.String("o", "-", "Output file/directory to create. Use -f to overwrite.") + flagVia = flag.String("via", "", "Fetch the blob via the given comma-separated sharerefs (dev only).") +) func main() { + client.AddFlags() flag.Parse() client := client.NewOrFail() diff --git a/clients/go/cammount/main.go b/clients/go/cammount/main.go index eefa6f555..d16fb842e 100644 --- a/clients/go/cammount/main.go +++ b/clients/go/cammount/main.go @@ -49,6 +49,7 @@ func main() { // Scans the arg list and sets up flags debug := flag.Bool("debug", false, "print debugging messages.") threaded := flag.Bool("threaded", true, "switch off threading; print debugging messages.") + client.AddFlags() flag.Parse() errorf := func(msg string, args ...interface{}) { diff --git a/clients/go/camput/camput.go b/clients/go/camput/camput.go index 1f05aa28b..5c371e9fd 100644 --- a/clients/go/camput/camput.go +++ b/clients/go/camput/camput.go @@ -531,6 +531,7 @@ func Save() { func main() { defer Save() jsonsign.AddFlags() + client.AddFlags() flag.Parse() if flag.NArg() == 0 { diff --git a/clients/go/camwebdav/main.go b/clients/go/camwebdav/main.go index e8a01eaa9..01f0c4235 100644 --- a/clients/go/camwebdav/main.go +++ b/clients/go/camwebdav/main.go @@ -27,6 +27,7 @@ var ( // TODO(rh): tame copy/paste code from cammount func main() { + client.AddFlags() flag.Parse() cacheDir, err := ioutil.TempDir("", "camlicache") if err != nil { diff --git a/lib/go/camli/client/config.go b/lib/go/camli/client/config.go index 9629ad97a..6250e2981 100644 --- a/lib/go/camli/client/config.go +++ b/lib/go/camli/client/config.go @@ -31,10 +31,16 @@ import ( "camli/osutil" ) -// These override the JSON config file ~/.camli/config "server" and -// "password" keys -var flagServer *string = flag.String("blobserver", "", "camlistore blob server") -var flagPassword *string = flag.String("password", "", "password for blob server") +// These, if set, override the JSON config file ~/.camli/config +// "server" and "password" keys. +// +// A main binary must call AddFlags to expose these. +var flagServer, flagPassword *string + +func AddFlags() { + flagServer = flag.String("blobserver", "", "camlistore blob server") + flagPassword = flag.String("password", "", "password for blob server") +} func ConfigFilePath() string { return filepath.Join(osutil.CamliConfigDir(), "config") @@ -66,7 +72,7 @@ func cleanServer(server string) string { } func blobServerOrDie() string { - if *flagServer != "" { + if flagServer != nil && *flagServer != "" { return cleanServer(*flagServer) } configOnce.Do(parseConfig) @@ -83,7 +89,7 @@ func blobServerOrDie() string { } func passwordOrDie() string { - if *flagPassword != "" { + if flagPassword != nil && *flagPassword != "" { return *flagPassword } configOnce.Do(parseConfig)