Autogenerate config, for the first time no more config generate
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
cast Copy files and folders from a single source to many destinations
|
||||
diff Compute differences between two files or folders
|
||||
access Set access permissions
|
||||
config Generate default configuration file [~/.mc/config.json]
|
||||
config Add new alias to default configuration file [~/.mc/config.json]
|
||||
update Check for new software updates
|
||||
```
|
||||
|
||||
@@ -26,7 +26,7 @@ Download ``mc`` from https://dl.minio.io:9000/updates/2015/Jun/linux-amd64/mc
|
||||
~~~
|
||||
$ wget https://dl.minio.io:9000/updates/2015/Jun/linux-amd64/mc
|
||||
$ chmod +x mc
|
||||
$ ./mc config generate
|
||||
$ ./mc
|
||||
~~~
|
||||
|
||||
#### OS X
|
||||
@@ -36,7 +36,7 @@ Download ``mc`` from https://dl.minio.io:9000/updates/2015/Jun/darwin-amd64/mc
|
||||
~~~
|
||||
$ curl https://dl.minio.io:9000/updates/2015/Jun/darwin-amd64/mc > mc
|
||||
$ chmod +x mc
|
||||
$ ./mc config generate
|
||||
$ ./mc
|
||||
~~~
|
||||
|
||||
#### Windows
|
||||
@@ -44,7 +44,7 @@ $ ./mc config generate
|
||||
Download ``mc`` from https://dl.minio.io:9000/updates/2015/Jun/windows-amd64/mc.exe
|
||||
|
||||
~~~
|
||||
C:\Users\Username\Downloads> mc.exe config generate
|
||||
C:\Users\Username\Downloads> mc.exe
|
||||
~~~
|
||||
|
||||
#### Source
|
||||
|
||||
@@ -64,9 +64,6 @@ func runAccessCmd(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
|
||||
}
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
|
||||
}
|
||||
config := mustGetMcConfig()
|
||||
acl := bucketACL(ctx.Args().First())
|
||||
if !acl.isValidBucketACL() {
|
||||
|
||||
@@ -54,9 +54,6 @@ func checkCastSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "cast", 1) // last argument is exit code.
|
||||
}
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
|
||||
}
|
||||
// extract URLs.
|
||||
URLs, err := args2URLs(ctx.Args())
|
||||
if err != nil {
|
||||
|
||||
@@ -64,9 +64,6 @@ func runCatCmd(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code
|
||||
}
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
|
||||
}
|
||||
config := mustGetMcConfig()
|
||||
// Convert arguments to URLs: expand alias, fix format...
|
||||
for _, arg := range ctx.Args() {
|
||||
|
||||
+7
-4
@@ -58,13 +58,16 @@ func (s *CmdTestSuite) SetUpSuite(c *C) {
|
||||
}
|
||||
setMcConfigDir(customConfigDir)
|
||||
|
||||
_, err = doConfig("generate", nil)
|
||||
err = createMcConfigDir()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
_, err = doConfig("generate", nil)
|
||||
c.Assert(err, Not(IsNil))
|
||||
config, err := newConfig()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
_, err = doConfig("cover", nil)
|
||||
err = writeConfig(config)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
_, err = doConfig("invalid", nil)
|
||||
c.Assert(err, Not(IsNil))
|
||||
|
||||
_, err = doConfig("alias", []string{"test", "https://test.io"})
|
||||
|
||||
+3
-23
@@ -37,20 +37,16 @@ import (
|
||||
//
|
||||
var configCmd = cli.Command{
|
||||
Name: "config",
|
||||
Usage: "Generate default configuration file [~/.mc/config.json]",
|
||||
Usage: "Add new alias to default configuration file [~/.mc/config.json]",
|
||||
Action: runConfigCmd,
|
||||
CustomHelpTemplate: `NAME:
|
||||
mc {{.Name}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} generate
|
||||
mc {{.Name}}{{if .Flags}} [ARGS...]{{end}} alias NAME HOSTURL
|
||||
|
||||
EXAMPLES:
|
||||
1. Generate mc config.
|
||||
$ mc config generate
|
||||
|
||||
2. Add alias URLs.
|
||||
1. Add alias URLs.
|
||||
$ mc config alias zek https://s3.amazonaws.com/
|
||||
|
||||
`,
|
||||
@@ -80,19 +76,6 @@ func runConfigCmd(ctx *cli.Context) {
|
||||
// saveConfig writes configuration data in json format to config file.
|
||||
func saveConfig(arg string, aliases []string) error {
|
||||
switch arg {
|
||||
case "generate":
|
||||
if isMcConfigExists() {
|
||||
return NewIodine(iodine.New(errConfigExists{}, nil))
|
||||
}
|
||||
config, err := newConfig()
|
||||
if err != nil {
|
||||
return NewIodine(iodine.New(err, nil))
|
||||
}
|
||||
err = writeConfig(config)
|
||||
if err != nil {
|
||||
return NewIodine(iodine.New(err, nil))
|
||||
}
|
||||
return nil
|
||||
case "alias":
|
||||
config, err := addAlias(aliases)
|
||||
if err != nil {
|
||||
@@ -125,15 +108,12 @@ func doConfig(arg string, aliases []string) (string, error) {
|
||||
return "Alias [" + aliases[1] + "] is invalid URL", NewIodine(iodine.New(err, nil))
|
||||
default:
|
||||
// unexpected error
|
||||
return "Unable to generate config file [" + configPath + "].", NewIodine(iodine.New(err, nil))
|
||||
return "Unable to modify config file [" + configPath + "].", NewIodine(iodine.New(err, nil))
|
||||
}
|
||||
}
|
||||
if arg == "alias" {
|
||||
return "Alias written to [" + configPath + "].", nil
|
||||
}
|
||||
if arg == "generate" {
|
||||
return "Configuration written to [" + configPath + "]. Please update your access credentials.", nil
|
||||
}
|
||||
return "", NewIodine(iodine.New(errUnexpected{}, nil))
|
||||
}
|
||||
|
||||
|
||||
@@ -61,9 +61,6 @@ func checkCopySyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "cp", 1) // last argument is exit code.
|
||||
}
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
|
||||
}
|
||||
// extract URLs.
|
||||
URLs, err := args2URLs(ctx.Args())
|
||||
if err != nil {
|
||||
|
||||
@@ -56,9 +56,6 @@ func runDiffCmd(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 2 || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "diff", 1) // last argument is exit code
|
||||
}
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
|
||||
}
|
||||
|
||||
config := mustGetMcConfig()
|
||||
firstURL := ctx.Args().First()
|
||||
|
||||
+3
-7
@@ -2,16 +2,12 @@
|
||||
|
||||
```go
|
||||
NAME:
|
||||
mc config - Generate configuration "${HOME}/.mc/config.json" file.
|
||||
mc config - Add new alias to default configuration "~/.mc/config.json" file.
|
||||
|
||||
USAGE:
|
||||
mc config generate
|
||||
mc config alias NAME HOSTURL
|
||||
mc config alias NAME HOSTURL
|
||||
|
||||
EXAMPLES:
|
||||
1. Generate mc config
|
||||
$ mc config generate
|
||||
|
||||
2. Add alias URLs
|
||||
1. Add alias URLs
|
||||
$ mc config alias zek https://s3.amazonaws.com/
|
||||
```
|
||||
|
||||
+11
-2
@@ -56,12 +56,21 @@ func checkGolangVersion() {
|
||||
func firstTimeRun() {
|
||||
if !isMcConfigExists() {
|
||||
if err := createMcConfigDir(); err != nil {
|
||||
console.Fatalf("Unable to create ‘mc’ folder. %s\n", err)
|
||||
console.Fatalf("Unable to create ‘mc’ config folder. %s\n", err)
|
||||
}
|
||||
config, err := newConfig()
|
||||
if err != nil {
|
||||
console.Fatalln(NewIodine(iodine.New(err, nil)))
|
||||
}
|
||||
err = writeConfig(config)
|
||||
if err != nil {
|
||||
console.Fatalln(NewIodine(iodine.New(err, nil)))
|
||||
}
|
||||
console.Infoln("Configuration written to [" + mustGetMcConfigPath() + "]. Please update your access credentials.")
|
||||
}
|
||||
if !isSessionDirExists() {
|
||||
if err := createSessionDir(); err != nil {
|
||||
console.Fatalf("Unable to create session folder. %s\n", err)
|
||||
console.Fatalf("Unable to create ‘mc’ session folder. %s\n", err)
|
||||
}
|
||||
}
|
||||
checkGolangVersion()
|
||||
|
||||
@@ -81,9 +81,6 @@ func runListCmd(ctx *cli.Context) {
|
||||
cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
|
||||
}
|
||||
config := mustGetMcConfig()
|
||||
for _, arg := range args {
|
||||
targetURL, err := getExpandedURL(arg, config.Aliases)
|
||||
|
||||
@@ -104,13 +104,6 @@ func registerBefore(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func registerAfter(ctx *cli.Context) error {
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func registerApp() *cli.App {
|
||||
// Register all the commands
|
||||
registerCmd(lsCmd) // List contents of a bucket
|
||||
@@ -174,7 +167,6 @@ func main() {
|
||||
|
||||
app := registerApp()
|
||||
app.Before = registerBefore
|
||||
app.After = registerAfter
|
||||
app.ExtraInfo = func() map[string]string {
|
||||
if globalDebugFlag {
|
||||
return getSystemData()
|
||||
|
||||
@@ -60,9 +60,6 @@ func runMakeBucketCmd(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code
|
||||
}
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
|
||||
}
|
||||
config := mustGetMcConfig()
|
||||
for _, arg := range ctx.Args() {
|
||||
targetURL, err := getExpandedURL(arg, config.Aliases)
|
||||
|
||||
@@ -63,10 +63,6 @@ type sessionV2 struct {
|
||||
|
||||
// newSessionV2 provides a new session
|
||||
func newSessionV2() *sessionV2 {
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
|
||||
}
|
||||
|
||||
s := &sessionV2{}
|
||||
s.Header = &sessionV2Header{}
|
||||
s.Header.Version = "1.1.0"
|
||||
|
||||
@@ -104,9 +104,6 @@ func runUpdateCmd(ctx *cli.Context) {
|
||||
if ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
|
||||
}
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", NewIodine(iodine.New(errNotConfigured{}, nil)))
|
||||
}
|
||||
msg, err := doUpdateCheck()
|
||||
if err != nil {
|
||||
console.Fatalln(msg)
|
||||
|
||||
Reference in New Issue
Block a user