From f06a4b20a3d9d164281e205586cab3a65415b4b4 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 28 Jan 2022 14:41:35 -0800 Subject: [PATCH] add missing 'mc admin inspect' examples (#3934) --- cmd/admin-inspect.go | 20 +++++++++++++++++++- cmd/admin-user-add.go | 2 ++ cmd/main.go | 31 +++++++++++++++++-------------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/cmd/admin-inspect.go b/cmd/admin-inspect.go index 476a5b5f..90d72e36 100644 --- a/cmd/admin-inspect.go +++ b/cmd/admin-inspect.go @@ -27,6 +27,8 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" + "strings" "time" "github.com/fatih/color" @@ -62,7 +64,15 @@ USAGE: FLAGS: {{range .VisibleFlags}}{{.}} {{end}} +EXAMPLES: + 1. Download 'xl.meta' for a specific object from all the drives in a zip file. + {{.Prompt}} {{.HelpName}} myminio/bucket/test*/xl.meta + 2. Download all constituent parts for a specific object, and optionally encrypt the downloaded zip. + {{.Prompt}} {{.HelpName}} --encrypt myminio/bucket/test*/*/part.* + + 3. Download recursively all objects at a prefix. NOTE: This can be an expensive operation use it with caution. + {{.Prompt}} {{.HelpName}} myminio/bucket/test/** `, } @@ -97,7 +107,15 @@ func mainAdminInspect(ctx *cli.Context) error { splits := splitStr(aliasedURL, "/", 3) bucket, prefix := splits[1], splits[2] - key, r, ierr := client.Inspect(context.Background(), madmin.InspectOptions{Volume: bucket, File: prefix}) + shellName, _ := getShellName() + if runtime.GOOS != "windows" && shellName != "bash" && strings.Contains(prefix, "*") { + console.Infoln("Your shell is auto determined as '" + shellName + "', wildcard patterns are only supported with 'bash' SHELL.") + } + + key, r, ierr := client.Inspect(context.Background(), madmin.InspectOptions{ + Volume: bucket, + File: prefix, + }) fatalIf(probe.NewError(ierr).Trace(aliasedURL), "Unable to inspect file.") // Create profile zip file diff --git a/cmd/admin-user-add.go b/cmd/admin-user-add.go index 47945962..17907db2 100644 --- a/cmd/admin-user-add.go +++ b/cmd/admin-user-add.go @@ -58,10 +58,12 @@ EXAMPLES: {{.DisableHistory}} {{.Prompt}} {{.HelpName}} myminio foobar foo12345 {{.EnableHistory}} + 2. Add a new user 'foobar' to MinIO server, prompting for keys. {{.Prompt}} {{.HelpName}} myminio Enter Access Key: foobar Enter Secret Key: foobar12345 + 3. Add a new user 'foobar' to MinIO server using piped keys. {{.DisableHistory}} {{.Prompt}} echo -e "foobar\nfoobar12345" | {{.HelpName}} myminio diff --git a/cmd/main.go b/cmd/main.go index 5e70a394..0130d216 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -36,6 +36,7 @@ import ( "github.com/inconshreveable/mousetrap" "github.com/minio/cli" "github.com/minio/mc/pkg/probe" + "github.com/minio/minio-go/v7/pkg/set" "github.com/minio/pkg/console" "github.com/minio/pkg/env" "github.com/minio/pkg/trie" @@ -299,12 +300,7 @@ func initMC() { loadRootCAs() } -func installAutoCompletion() { - if runtime.GOOS == "windows" { - console.Infoln("autocompletion feature is not available for this operating system") - return - } - +func getShellName() (string, bool) { shellName := os.Getenv("SHELL") if shellName == "" { ppid := os.Getppid() @@ -315,19 +311,26 @@ func installAutoCompletion() { "no SHELL environment variable found") } shellName = strings.TrimSpace(string(ppName)) + return strings.ToLower(filepath.Base(shellName)), false + } + return strings.ToLower(filepath.Base(shellName)), true +} + +func installAutoCompletion() { + if runtime.GOOS == "windows" { + console.Infoln("autocompletion feature is not available for this operating system") + return + } + + shellName, ok := getShellName() + if !ok { console.Infoln("No 'SHELL' env var. Your shell is auto determined as '" + shellName + "'.") } else { console.Infoln("Your shell is set to '" + shellName + "', by env var 'SHELL'.") } - shellName = strings.ToLower(filepath.Base(shellName)) - supportedShells := map[string]bool{ - "bash": true, - "zsh": true, - "fish": true, - } - - if !supportedShells[shellName] { + supportedShellsSet := set.CreateStringSet("bash", "zsh", "fish") + if !supportedShellsSet.Contains(shellName) { fatalIf(probe.NewError(errors.New("")), "'"+shellName+"' is not a supported shell. "+ "Supported shells are: bash, zsh, fish")