Add a way to update alias using --alias <aliasname> <url>
This commit is contained in:
@@ -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
|
||||
|
||||
+6
-1
@@ -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.",
|
||||
|
||||
Reference in New Issue
Block a user