Merge pull request #131 from harshavardhana/pr_out_move_bash_completion_to_mc_config_subcommand
This commit is contained in:
@@ -17,8 +17,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -47,23 +45,6 @@ func startBar(size int64) *pb.ProgressBar {
|
||||
return bar
|
||||
}
|
||||
|
||||
// getBashCompletion -
|
||||
func getBashCompletion() {
|
||||
var b bytes.Buffer
|
||||
b.WriteString(mcBashCompletion)
|
||||
f := getMcBashCompletionFilename()
|
||||
fl, err := os.OpenFile(f, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
defer fl.Close()
|
||||
_, err = fl.Write(b.Bytes())
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
msg := "\nConfiguration written to " + f
|
||||
msg = msg + "\n\n$ source ${HOME}/.minio/mc/mc.bash_completion\n"
|
||||
msg = msg + "$ echo 'source ${HOME}/.minio/mc/mc.bash_completion' >> ${HOME}/.bashrc\n"
|
||||
info(msg)
|
||||
}
|
||||
|
||||
// NewClient - get new client
|
||||
func getNewClient(c *cli.Context) (*s3.Client, error) {
|
||||
var client *s3.Client
|
||||
@@ -89,16 +70,6 @@ func getNewClient(c *cli.Context) (*s3.Client, error) {
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// Parse global options
|
||||
func parseGlobalOptions(c *cli.Context) {
|
||||
switch {
|
||||
case c.Bool("get-bash-completion") == true:
|
||||
getBashCompletion()
|
||||
default:
|
||||
cli.ShowAppHelp(c)
|
||||
}
|
||||
}
|
||||
|
||||
// Parse subcommand options
|
||||
func parseArgs(c *cli.Context) (args *cmdArgs, err error) {
|
||||
args = new(cmdArgs)
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os/user"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/mc/pkg/s3"
|
||||
)
|
||||
@@ -53,7 +55,27 @@ func getMcConfig() (config *mcConfig, err error) {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func parseConfigureInput(c *cli.Context) (config *mcConfig, err error) {
|
||||
// getBashCompletion -
|
||||
func getBashCompletion() {
|
||||
var b bytes.Buffer
|
||||
if os.Getenv("SHELL") != "/bin/bash" {
|
||||
fatal("Unsupported shell for bash completion detected.. exiting")
|
||||
}
|
||||
b.WriteString(mcBashCompletion)
|
||||
f := getMcBashCompletionFilename()
|
||||
fl, err := os.OpenFile(f, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
defer fl.Close()
|
||||
_, err = fl.Write(b.Bytes())
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
msg := "\nConfiguration written to " + f
|
||||
msg = msg + "\n\n$ source ${HOME}/.minio/mc/mc.bash_completion\n"
|
||||
msg = msg + "$ echo 'source ${HOME}/.minio/mc/mc.bash_completion' >> ${HOME}/.bashrc\n"
|
||||
info(msg)
|
||||
}
|
||||
|
||||
func parseConfigInput(c *cli.Context) (config *mcConfig, err error) {
|
||||
accessKey := c.String("accesskey")
|
||||
secretKey := c.String("secretkey")
|
||||
config = &mcConfig{
|
||||
@@ -65,11 +87,14 @@ func parseConfigureInput(c *cli.Context) (config *mcConfig, err error) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if c.Bool("completion") {
|
||||
getBashCompletion()
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func doConfigure(c *cli.Context) {
|
||||
configData, err := parseConfigureInput(c)
|
||||
func doConfig(c *cli.Context) {
|
||||
configData, err := parseConfigInput(c)
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
+7
-7
@@ -47,7 +47,7 @@ var mb = cli.Command{
|
||||
Action: doFsMb,
|
||||
}
|
||||
|
||||
var configure = cli.Command{
|
||||
var config = cli.Command{
|
||||
Name: "config",
|
||||
Usage: "Generate configuration \"" + getMcConfigFilename() + "\" file.",
|
||||
Description: `Configure minio client configuration data. If your config
|
||||
@@ -55,7 +55,7 @@ var configure = cli.Command{
|
||||
automatically created for you. Note that the configure command only writes
|
||||
values to the config file. It does not use any configuration values from
|
||||
the environment variables.`,
|
||||
Action: doConfigure,
|
||||
Action: doConfig,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "accesskey, a",
|
||||
@@ -67,6 +67,10 @@ var configure = cli.Command{
|
||||
Value: "",
|
||||
Usage: "AWS secret key id",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "completion",
|
||||
Usage: "Generate bash completion \"" + getMcBashCompletionFilename() + "\" file.",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -87,7 +91,7 @@ var options = []cli.Command{
|
||||
cp,
|
||||
ls,
|
||||
mb,
|
||||
configure,
|
||||
config,
|
||||
}
|
||||
|
||||
var flags = []cli.Flag{
|
||||
@@ -99,10 +103,6 @@ var flags = []cli.Flag{
|
||||
Name: "quiet, q",
|
||||
Usage: "disable chatty output, such as the progress bar",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "get-bash-completion",
|
||||
Usage: "Generate bash completion \"" + getMcBashCompletionFilename() + "\" file.",
|
||||
},
|
||||
}
|
||||
|
||||
var mcBashCompletion = `#!/bin/bash
|
||||
|
||||
Reference in New Issue
Block a user