Merge pull request #313 from fkautz/pr_out_removing_fatal_side_effects_from_get_bash_completion_config

This commit is contained in:
Frederick F. Kautz IV
2015-04-10 17:50:55 -07:00
4 changed files with 46 additions and 10 deletions
+10 -8
View File
@@ -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 -
+29
View File
@@ -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)
}
+6 -1
View File
@@ -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 {
+1 -1
View File
@@ -145,7 +145,7 @@ EXAMPLES:
},
cli.BoolFlag{
Name: "completion",
Usage: "Generate bash completion \"" + getMcBashCompletionFilename() + "\" file.",
Usage: "Generate bash completion \"" + mustGetMcBashCompletionFilename() + "\" file.",
},
},
}