new help command
This commit is contained in:
+2
-2
@@ -91,13 +91,13 @@ func (s accessMessage) JSON() string {
|
||||
}
|
||||
|
||||
func checkAccessSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
if !ctx.Args().Present() {
|
||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
|
||||
}
|
||||
if len(ctx.Args()) < 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
|
||||
}
|
||||
switch ctx.Args().Get(0) {
|
||||
switch ctx.Args().First() {
|
||||
case "set":
|
||||
if len(ctx.Args().Tail()) < 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ EXAMPLES:
|
||||
|
||||
// checkCatSyntax performs command-line input validation for cat command.
|
||||
func checkCatSyntax(ctx *cli.Context) {
|
||||
if (!ctx.Args().Present() && !globalMimicFlag) || ctx.Args().First() == "help" {
|
||||
if !ctx.Args().Present() && !globalMimicFlag {
|
||||
cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ COMMANDS:
|
||||
|
||||
// mainConfig is the handle for "mc config" command. provides sub-commands which write configuration data in json format to config file.
|
||||
func mainConfig(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
if !ctx.Args().Present() {
|
||||
cli.ShowAppHelp(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ const (
|
||||
// C: copy(*, d...)
|
||||
//
|
||||
func checkCopySyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
|
||||
if len(ctx.Args()) < 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "cp", 1) // last argument is exit code.
|
||||
}
|
||||
// extract URLs.
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ EXAMPLES:
|
||||
}
|
||||
|
||||
func checkDiffSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 2 || ctx.Args().First() == "help" {
|
||||
if len(ctx.Args()) != 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "diff", 1) // last argument is exit code
|
||||
}
|
||||
for _, arg := range ctx.Args() {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Minio Client (C) 2014, 2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
// Help command.
|
||||
var helpCmd = cli.Command{
|
||||
Name: "help",
|
||||
Usage: "Show help.",
|
||||
Action: mainHelp,
|
||||
CustomHelpTemplate: `NAME:
|
||||
mc {{.Name}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
mc {{.Name}} [COMMAND]
|
||||
|
||||
EXAMPLES:
|
||||
1. Show mc usage, commands and global flags.
|
||||
$ mc {{.Name}}
|
||||
|
||||
2. Show help for a command.
|
||||
$ mc {{.Name}} share
|
||||
`,
|
||||
}
|
||||
|
||||
// Validate command line arguments.
|
||||
func checkHelpSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) > 1 { // Accepts a maximum of 1 argument.
|
||||
exitCode := 1
|
||||
cli.ShowCommandHelpAndExit(ctx, "help", exitCode)
|
||||
}
|
||||
}
|
||||
|
||||
// main for help command.
|
||||
func mainHelp(ctx *cli.Context) {
|
||||
checkHelpSyntax(ctx)
|
||||
|
||||
if ctx.Args().First() != "" { // command help.
|
||||
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||
} else { // mc help.
|
||||
cli.ShowAppHelp(ctx)
|
||||
}
|
||||
}
|
||||
+1
-14
@@ -51,36 +51,25 @@ OPTIONS:
|
||||
EXAMPLES:
|
||||
1. List buckets on Amazon S3 cloud storage.
|
||||
$ mc {{.Name}} https://s3.amazonaws.com/
|
||||
[2015-01-20 15:42:00 PST] 0B rom/
|
||||
[2015-01-15 00:05:40 PST] 0B zek/
|
||||
|
||||
2. List buckets and all its contents from Amazon S3 cloud storage recursively.
|
||||
$ mc {{.Name}} https://s3.amazonaws.com/...
|
||||
2015-01-15 00:05:40 PST 0B zek/
|
||||
2015-03-31 14:46:33 PDT 55MiB backup.tar.gz
|
||||
2015-04-15 20:11:22 PST 0B miniocloud
|
||||
|
||||
3. List files recursively on a local filesystem on Microsoft Windows.
|
||||
$ mc {{.Name}} C:\Users\Worf\...
|
||||
[2015-03-31 14:46:33 PDT] 15.00MiB Gowron\Khitomer Conference Details.pdf
|
||||
...
|
||||
|
||||
4. List files with non-English characters on Amazon S3 cloud storage.
|
||||
$ mc {{.Name}} s3/andoria/本...
|
||||
[2015-05-19 17:28:22 PDT] 41B 本語.md
|
||||
|
||||
5. List folders with space separated names on Amazon S3 cloud storage.
|
||||
$ mc {{.Name}} 's3/miniocloud/Community Files/'
|
||||
[2015-05-19 17:28:22 PDT] 41B 本語.md
|
||||
|
||||
6. Behave like operating system ‘ls’ tool. Useful for aliasing.
|
||||
$ alias ls='mc --mimic ls'
|
||||
$ {{.Name}}
|
||||
[2015-05-19 17:28:22 PDT] 41B 本語.md
|
||||
|
||||
7. List incomplete (previously failed) uploads of objects on Amazon S3.
|
||||
$ mc {{.Name}} --incomplete s3/mybucket
|
||||
[2015-10-19 22:28:02 PDT] 41MiB backup/server112-11Nov15.tgz
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -94,9 +83,7 @@ func checkListSyntax(ctx *cli.Context) {
|
||||
cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
if ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
for _, arg := range args {
|
||||
if strings.TrimSpace(arg) == "" {
|
||||
fatalIf(errInvalidArgument().Trace(), "Unable to validate empty argument.")
|
||||
|
||||
@@ -139,6 +139,7 @@ func findClosestCommands(command string) []string {
|
||||
|
||||
func registerApp() *cli.App {
|
||||
// Register all the commands (refer flags.go)
|
||||
registerCmd(helpCmd) // List contents of a bucket.
|
||||
registerCmd(lsCmd) // List contents of a bucket.
|
||||
registerCmd(mbCmd) // Make a bucket.
|
||||
registerCmd(catCmd) // Display contents of a file.
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ func (s makeBucketMessage) JSON() string {
|
||||
|
||||
// Validate command line arguments.
|
||||
func checkMakeBucketSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
if !ctx.Args().Present() {
|
||||
cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code
|
||||
}
|
||||
for _, arg := range ctx.Args() {
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ func (m mirrorURLs) isEmpty() bool {
|
||||
|
||||
// checkMirrorSyntax(URLs []string)
|
||||
func checkMirrorSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
|
||||
if len(ctx.Args()) < 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "mirror", 1) // last argument is exit code.
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ EXAMPLES:
|
||||
|
||||
// checkPipeSyntax performs command-line input validation for pipe command.
|
||||
func checkPipeSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
if !ctx.Args().Present() {
|
||||
cli.ShowCommandHelpAndExit(ctx, "pipe", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -104,11 +104,9 @@ func (r rmMessage) JSON() string {
|
||||
// Validate command line arguments.
|
||||
func checkRmSyntax(ctx *cli.Context) {
|
||||
args := ctx.Args()
|
||||
|
||||
ishelp := ctx.GlobalBool("help")
|
||||
isForce := ctx.Bool("force")
|
||||
|
||||
if !args.Present() || ishelp {
|
||||
if !args.Present() {
|
||||
exitCode := 1
|
||||
cli.ShowCommandHelpAndExit(ctx, "rm", exitCode)
|
||||
}
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ func sessionExecute(s *sessionV3) {
|
||||
}
|
||||
|
||||
func checkSessionSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 1 || ctx.Args().First() == "help" {
|
||||
if len(ctx.Args()) < 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "session", 1) // last argument is exit code
|
||||
}
|
||||
if strings.TrimSpace(ctx.Args().First()) == "" {
|
||||
|
||||
+1
-2
@@ -42,14 +42,13 @@ USAGE:
|
||||
{{.Name}} command [arguments...]
|
||||
|
||||
COMMANDS:
|
||||
{{range .Commands}}{{ .Name }}{{ "\t" }}{{.Usage}}
|
||||
{{range .Subcommands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
|
||||
{{end}}
|
||||
`,
|
||||
}
|
||||
|
||||
// migrateShare migrate to newest version sequentially
|
||||
func migrateShare() {
|
||||
|
||||
if !isShareDirExists() {
|
||||
return
|
||||
}
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ func (u updateMessage) JSON() string {
|
||||
|
||||
// check valid input arguments.
|
||||
func checkUpdateSyntax(ctx *cli.Context) {
|
||||
if ctx.Args().First() == "help" || !ctx.Args().Present() {
|
||||
if !ctx.Args().Present() {
|
||||
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
|
||||
}
|
||||
arg := strings.TrimSpace(ctx.Args().First())
|
||||
|
||||
@@ -41,10 +41,6 @@ USAGE:
|
||||
}
|
||||
|
||||
func mainVersion(ctx *cli.Context) {
|
||||
if ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
// Additional command speific theme customization.
|
||||
console.SetColor("Version", color.New(color.FgGreen, color.Bold))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user