diff --git a/cmd-common.go b/cmd-common.go index c71636e3..2392bed7 100644 --- a/cmd-common.go +++ b/cmd-common.go @@ -17,17 +17,15 @@ package main import ( + "net/http" "path" "time" - "net/http" - "github.com/cheggaaa/pb" "github.com/minio-io/mc/pkg/client" "github.com/minio-io/mc/pkg/client/s3" "github.com/minio-io/mc/pkg/console" "github.com/minio-io/minio/pkg/iodine" - "github.com/minio-io/minio/pkg/utils/log" ) // StartBar -- instantiate a progressbar @@ -46,13 +44,17 @@ func startBar(size int64) *pb.ProgressBar { return bar } -func getMcBashCompletionFilename() string { - configDir, err := getOrCreateMcConfigDir() +func getMcBashCompletionFilename() (string, error) { + configDir, err := getMcConfigDir() if err != nil { - log.Debug.Println(iodine.New(err, nil)) - log.Fatalln("Unable to get mc config directory") + return "", err } - return path.Join(configDir, "mc.bash_completion") + return path.Join(configDir, "mc.bash_completion"), nil +} + +func mustGetMcBashCompletionFilename() string { + p, _ := getMcBashCompletionFilename() + return p } // getTraceTransport - diff --git a/cmd-common_test.go b/cmd-common_test.go new file mode 100644 index 00000000..bec45c3f --- /dev/null +++ b/cmd-common_test.go @@ -0,0 +1,29 @@ +package main + +import ( + "github.com/cheggaaa/pb" + . "github.com/minio-io/check" + "strings" + "time" +) + +var _ = Suite(&MySuite{}) + +func (s *MySuite) TestStatusBar(c *C) { + bar := startBar(1024) + c.Assert(bar, Not(IsNil)) + c.Assert(bar.Units, Equals, pb.U_BYTES) + c.Assert(bar.RefreshRate, Equals, time.Millisecond*10) + c.Assert(bar.NotPrint, Equals, true) + c.Assert(bar.ShowSpeed, Equals, true) +} + +func (s *MySuite) TestBashCompletionFilename(c *C) { + file, err := getMcBashCompletionFilename() + c.Assert(err, IsNil) + c.Assert(file, Not(Equals), "mc.bash_completion") + c.Assert(strings.HasSuffix(file, "mc.bash_completion"), Equals, true) + + file2 := mustGetMcBashCompletionFilename() + c.Assert(file, Equals, file2) +} diff --git a/cmd-config.go b/cmd-config.go index 4ae12b44..362416ae 100644 --- a/cmd-config.go +++ b/cmd-config.go @@ -326,13 +326,18 @@ func getHostConfig(requestURL string) (*hostConfig, error) { } //getBashCompletionCmd generates bash completion file. +// TODO don't kill, return an error instead. caller should kill, not this function func getBashCompletionCmd() { var b bytes.Buffer if os.Getenv("SHELL") != "/bin/bash" { console.Fatalln("Unsupported shell for bash completion detected.. exiting") } b.WriteString(mcBashCompletion) - f := getMcBashCompletionFilename() + f, _ := getMcBashCompletionFilename() + // TODO uncomment when ready + // if err != nil { + // return err + // } fl, err := os.OpenFile(f, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) defer fl.Close() if err != nil { diff --git a/cmd-options.go b/cmd-options.go index ace2e81f..d170d716 100644 --- a/cmd-options.go +++ b/cmd-options.go @@ -145,7 +145,7 @@ EXAMPLES: }, cli.BoolFlag{ Name: "completion", - Usage: "Generate bash completion \"" + getMcBashCompletionFilename() + "\" file.", + Usage: "Generate bash completion \"" + mustGetMcBashCompletionFilename() + "\" file.", }, }, }