camput: move debug flag registration to its own func, for use by tests later.

Also, don't call TransportForConfig on client when we're in blobdir mode.
Avoids a warning.

Change-Id: I5d618b7ab7d701b4c9d9086c8adedef7b447f62b
This commit is contained in:
Brad Fitzpatrick 2014-02-18 21:24:52 -08:00
parent 1509f266be
commit 53ec1b496c
1 changed files with 20 additions and 14 deletions

View File

@ -48,11 +48,17 @@ var (
uploader *Uploader // initialized by getUploader
)
func init() {
if debug, _ := strconv.ParseBool(os.Getenv("CAMLI_DEBUG")); debug {
var debugFlagOnce sync.Once
func registerDebugFlags() {
flag.BoolVar(&flagProxyLocal, "proxy_local", false, "If true, the HTTP_PROXY environment is also used for localhost requests. This can be helpful during debugging.")
flag.BoolVar(&flagHaveCache, "havecache", true, "Use the 'have cache', a cache keeping track of what blobs the remote server should already have from previous uploads.")
}
func init() {
if debug, _ := strconv.ParseBool(os.Getenv("CAMLI_DEBUG")); debug {
debugFlagOnce.Do(registerDebugFlags)
}
cmdmain.ExtraFlagRegistration = func() {
client.AddFlags()
}
@ -125,6 +131,7 @@ func proxyFromEnvironment(req *http.Request) (*url.URL, error) {
func newUploader() *Uploader {
var cc *client.Client
var httpStats *httputil.StatsTransport
if d := *flagBlobDir; d != "" {
ss, err := dir.New(d)
if err != nil {
@ -133,11 +140,6 @@ func newUploader() *Uploader {
cc = client.NewStorageClient(ss)
} else {
cc = client.NewOrFail()
}
if !*cmdmain.FlagVerbose {
cc.SetLogger(nil)
}
proxy := http.ProxyFromEnvironment
if flagProxyLocal {
proxy = proxyFromEnvironment
@ -147,8 +149,12 @@ func newUploader() *Uploader {
Proxy: proxy,
Verbose: *flagHTTP,
})
httpStats, _ := tr.(*httputil.StatsTransport)
httpStats, _ = tr.(*httputil.StatsTransport)
cc.SetHTTPClient(&http.Client{Transport: tr})
}
if !*cmdmain.FlagVerbose {
cc.SetLogger(nil)
}
pwd, err := os.Getwd()
if err != nil {