diff --git a/cmd-config.go b/cmd-config.go index c3f8ca6a..834f59c1 100644 --- a/cmd-config.go +++ b/cmd-config.go @@ -2,9 +2,11 @@ package main import ( "bytes" + "errors" "fmt" "os" "path" + "strings" "encoding/json" "io/ioutil" @@ -139,6 +141,23 @@ func getBashCompletion() { func parseConfigInput(c *cli.Context) (config *mcConfig, err error) { accessKey := c.String("accesskey") secretKey := c.String("secretkey") + + alias := strings.Fields(c.String("alias")) + if len(alias) == 0 { + // valid case throw help + return nil, nil + } + if len(alias) != 2 { + return nil, errors.New("invalid number of arguments for --alias, requires exact 2") + } + aliasName := alias[0] + url := alias[1] + if strings.HasPrefix(aliasName, "http") { + return nil, errors.New("invalid alias cannot use http{s}") + } + if !strings.HasPrefix(url, "http") { + return nil, errors.New("invalid url type only supports http{s}") + } config = &mcConfig{ Version: currentConfigVersion, S3: s3Config{ @@ -156,6 +175,10 @@ func parseConfigInput(c *cli.Context) (config *mcConfig, err error) { Name: "localhost", URL: "http://localhost:9000/", }, + { + Name: aliasName, + URL: url, + }, }, } return config, nil diff --git a/cmd-options.go b/cmd-options.go index 19032da1..cde36e4d 100644 --- a/cmd-options.go +++ b/cmd-options.go @@ -58,7 +58,7 @@ var configCmd = cli.Command{ Action: doConfig, Flags: []cli.Flag{ cli.StringFlag{ - Name: "accesskey, a", + Name: "accesskey, k", Value: "", Usage: "AWS access key id", }, @@ -67,6 +67,11 @@ var configCmd = cli.Command{ Value: "", Usage: "AWS secret key id", }, + cli.StringFlag{ + Name: "alias", + Value: "", + Usage: "Add aliases into config", + }, cli.BoolFlag{ Name: "completion", Usage: "Generate bash completion \"" + getMcBashCompletionFilename() + "\" file.",