From b7a3dff2872b6bd7c28c7e46d9b0273517912ef5 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Mon, 12 Oct 2020 17:53:51 +0100 Subject: [PATCH] Fix 'did you mean' message (#3448) --- cmd/admin-bucket-remote-main.go | 24 +++++++++++--------- cmd/admin-bucket.go | 22 +++++++++--------- cmd/admin-config.go | 32 +++++++++++++------------- cmd/admin-group.go | 30 +++++++++++++------------ cmd/admin-kms-key.go | 22 +++++++++--------- cmd/admin-kms.go | 20 +++++++++-------- cmd/admin-main.go | 40 +++++++++++++++++---------------- cmd/admin-policy.go | 28 ++++++++++++----------- cmd/admin-profile.go | 22 +++++++++--------- cmd/admin-prometheus.go | 10 +++++---- cmd/admin-service.go | 12 +++++----- cmd/admin-top.go | 20 +++++++++-------- cmd/admin-user.go | 30 +++++++++++++------------ cmd/alias-main.go | 14 +++++++----- cmd/encrypt-main.go | 14 +++++++----- cmd/event-main.go | 14 +++++++----- cmd/flags.go | 13 ----------- cmd/ilm-main.go | 22 +++++++++--------- cmd/legalhold-main.go | 24 +++++++++++--------- cmd/main.go | 34 ++++++++++++++++++---------- cmd/replicate-main.go | 20 +++++++++-------- cmd/retention-main.go | 24 +++++++++++--------- cmd/share-main.go | 14 +++++++----- cmd/tag-main.go | 14 +++++++----- cmd/version-main.go | 14 +++++++----- 25 files changed, 288 insertions(+), 245 deletions(-) diff --git a/cmd/admin-bucket-remote-main.go b/cmd/admin-bucket-remote-main.go index da2d22bb..01cc0e44 100644 --- a/cmd/admin-bucket-remote-main.go +++ b/cmd/admin-bucket-remote-main.go @@ -18,23 +18,25 @@ package cmd import "github.com/minio/cli" +var adminBucketRemoteSubcommands = []cli.Command{ + adminBucketRemoteAddCmd, + adminBucketRemoteListCmd, + adminBucketRemoteRmCmd, +} + var adminBucketRemoteCmd = cli.Command{ - Name: "remote", - Usage: "configure remote target buckets", - Action: mainadminBucketRemote, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - adminBucketRemoteAddCmd, - adminBucketRemoteListCmd, - adminBucketRemoteRmCmd, - }, + Name: "remote", + Usage: "configure remote target buckets", + Action: mainadminBucketRemote, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: adminBucketRemoteSubcommands, HideHelpCommand: true, } // mainadminBucketRemote is the handle for "mc admin bucket remote" command. func mainadminBucketRemote(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminBucketRemoteSubcommands) return nil // Sub-commands like "add", "ls", "rm" have their own main. } diff --git a/cmd/admin-bucket.go b/cmd/admin-bucket.go index 3eb84ab8..0095afe1 100644 --- a/cmd/admin-bucket.go +++ b/cmd/admin-bucket.go @@ -18,22 +18,24 @@ package cmd import "github.com/minio/cli" +var adminBucketSubcommands = []cli.Command{ + adminBucketQuotaCmd, + adminBucketRemoteCmd, +} + var adminBucketCmd = cli.Command{ - Name: "bucket", - Usage: "manage buckets defined in the MinIO server", - Action: mainAdminBucket, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - adminBucketQuotaCmd, - adminBucketRemoteCmd, - }, + Name: "bucket", + Usage: "manage buckets defined in the MinIO server", + Action: mainAdminBucket, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: adminBucketSubcommands, HideHelpCommand: true, } // mainAdminBucket is the handle for "mc admin bucket" command. func mainAdminBucket(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminBucketSubcommands) return nil // Sub-commands like "quota", "remote" have their own main. } diff --git a/cmd/admin-config.go b/cmd/admin-config.go index c6ef8e23..71178135 100644 --- a/cmd/admin-config.go +++ b/cmd/admin-config.go @@ -18,27 +18,29 @@ package cmd import "github.com/minio/cli" +var adminConfigSubcommands = []cli.Command{ + adminConfigGetCmd, + adminConfigSetCmd, + adminConfigResetCmd, + adminConfigHistoryCmd, + adminConfigRestoreCmd, + adminConfigExportCmd, + adminConfigImportCmd, +} + var adminConfigCmd = cli.Command{ - Name: "config", - Usage: "manage MinIO server configuration", - Action: mainAdminConfig, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - adminConfigGetCmd, - adminConfigSetCmd, - adminConfigResetCmd, - adminConfigHistoryCmd, - adminConfigRestoreCmd, - adminConfigExportCmd, - adminConfigImportCmd, - }, + Name: "config", + Usage: "manage MinIO server configuration", + Action: mainAdminConfig, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: adminConfigSubcommands, HideHelpCommand: true, } // mainAdminConfig is the handle for "mc admin config" command. func mainAdminConfig(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminConfigSubcommands) return nil // Sub-commands like "get", "set" have their own main. } diff --git a/cmd/admin-group.go b/cmd/admin-group.go index b6d36be5..92aa090b 100644 --- a/cmd/admin-group.go +++ b/cmd/admin-group.go @@ -18,26 +18,28 @@ package cmd import "github.com/minio/cli" +var adminGroupSubcommands = []cli.Command{ + adminGroupAddCmd, + adminGroupRemoveCmd, + adminGroupInfoCmd, + adminGroupListCmd, + adminGroupEnableCmd, + adminGroupDisableCmd, +} + var adminGroupCmd = cli.Command{ - Name: "group", - Usage: "manage groups", - Action: mainAdminGroup, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - adminGroupAddCmd, - adminGroupRemoveCmd, - adminGroupInfoCmd, - adminGroupListCmd, - adminGroupEnableCmd, - adminGroupDisableCmd, - }, + Name: "group", + Usage: "manage groups", + Action: mainAdminGroup, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: adminGroupSubcommands, HideHelpCommand: true, } // mainAdminGroup is the handle for "mc admin config" command. func mainAdminGroup(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminGroupSubcommands) return nil // Sub-commands like "get", "set" have their own main. } diff --git a/cmd/admin-kms-key.go b/cmd/admin-kms-key.go index defac930..3549ebe1 100644 --- a/cmd/admin-kms-key.go +++ b/cmd/admin-kms-key.go @@ -18,21 +18,23 @@ package cmd import "github.com/minio/cli" +var adminKMSKeySubcommands = []cli.Command{ + adminKMSCreateKeyCmd, + adminKMSKeyStatusCmd, +} + var adminKMSKeyCmd = cli.Command{ - Name: "key", - Usage: "manage KMS master keys: Request key status information", - Action: mainAdminKMSKey, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - adminKMSCreateKeyCmd, - adminKMSKeyStatusCmd, - }, + Name: "key", + Usage: "manage KMS master keys: Request key status information", + Action: mainAdminKMSKey, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: adminKMSKeySubcommands, HideHelpCommand: true, } // mainAdminKMSKey is the handle for the "mc admin kms key" command. func mainAdminKMSKey(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminKMSKeySubcommands) return nil } diff --git a/cmd/admin-kms.go b/cmd/admin-kms.go index e521edf6..70f2703d 100644 --- a/cmd/admin-kms.go +++ b/cmd/admin-kms.go @@ -18,20 +18,22 @@ package cmd import "github.com/minio/cli" +var adminKMSSubcommands = []cli.Command{ + adminKMSKeyCmd, +} + var adminKMSCmd = cli.Command{ - Name: "kms", - Usage: "perform KMS management operations", - Action: mainAdminKMS, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - adminKMSKeyCmd, - }, + Name: "kms", + Usage: "perform KMS management operations", + Action: mainAdminKMS, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: adminKMSSubcommands, HideHelpCommand: true, } // mainAdminKMS is the handle for the "mc admin kms" command. func mainAdminKMS(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminKMSSubcommands) return nil } diff --git a/cmd/admin-main.go b/cmd/admin-main.go index ee3793b2..f965d2ac 100644 --- a/cmd/admin-main.go +++ b/cmd/admin-main.go @@ -29,38 +29,40 @@ const ( check = "✔" ) +var adminCmdSubcommands = []cli.Command{ + adminServiceCmd, + adminServerUpdateCmd, + adminInfoCmd, + adminUserCmd, + adminGroupCmd, + adminPolicyCmd, + adminConfigCmd, + adminHealCmd, + adminProfileCmd, + adminTopCmd, + adminTraceCmd, + adminConsoleCmd, + adminPrometheusCmd, + adminKMSCmd, + adminOBDCmd, + adminBucketCmd, +} + var adminCmd = cli.Command{ Name: "admin", Usage: "manage MinIO servers", Action: mainAdmin, + Subcommands: adminCmdSubcommands, HideHelpCommand: true, Before: setGlobalsFromContext, Flags: append(adminFlags, globalFlags...), - Subcommands: []cli.Command{ - adminServiceCmd, - adminServerUpdateCmd, - adminInfoCmd, - adminUserCmd, - adminGroupCmd, - adminPolicyCmd, - adminConfigCmd, - adminHealCmd, - adminProfileCmd, - adminTopCmd, - adminTraceCmd, - adminConsoleCmd, - adminPrometheusCmd, - adminKMSCmd, - adminOBDCmd, - adminBucketCmd, - }, } const dateTimeFormatFilename = "2006-01-02T15-04-05.999999-07-00" // mainAdmin is the handle for "mc admin" command. func mainAdmin(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminCmdSubcommands) return nil // Sub-commands like "service", "heal", "top" have their own main. } diff --git a/cmd/admin-policy.go b/cmd/admin-policy.go index e727b6bd..7efc8ec7 100644 --- a/cmd/admin-policy.go +++ b/cmd/admin-policy.go @@ -18,25 +18,27 @@ package cmd import "github.com/minio/cli" +var adminPolicySubcommands = []cli.Command{ + adminPolicyAddCmd, + adminPolicyRemoveCmd, + adminPolicyListCmd, + adminPolicyInfoCmd, + adminPolicySetCmd, +} + var adminPolicyCmd = cli.Command{ - Name: "policy", - Usage: "manage policies defined in the MinIO server", - Action: mainAdminPolicy, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - adminPolicyAddCmd, - adminPolicyRemoveCmd, - adminPolicyListCmd, - adminPolicyInfoCmd, - adminPolicySetCmd, - }, + Name: "policy", + Usage: "manage policies defined in the MinIO server", + Action: mainAdminPolicy, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: adminPolicySubcommands, HideHelpCommand: true, } // mainAdminPolicy is the handle for "mc admin policy" command. func mainAdminPolicy(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminPolicySubcommands) return nil // Sub-commands like "get", "set" have their own main. } diff --git a/cmd/admin-profile.go b/cmd/admin-profile.go index 79373ffb..72c790e7 100644 --- a/cmd/admin-profile.go +++ b/cmd/admin-profile.go @@ -20,21 +20,23 @@ import ( "github.com/minio/cli" ) +var adminProfileSubcommands = []cli.Command{ + adminProfileStartCmd, + adminProfileStopCmd, +} + var adminProfileCmd = cli.Command{ - Name: "profile", - Usage: "generate profile data for debugging purposes", - Action: mainAdminProfile, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - adminProfileStartCmd, - adminProfileStopCmd, - }, + Name: "profile", + Usage: "generate profile data for debugging purposes", + Action: mainAdminProfile, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: adminProfileSubcommands, HideHelpCommand: true, } // mainAdminProfile is the handle for "mc admin profile" command. func mainAdminProfile(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminProfileSubcommands) return nil } diff --git a/cmd/admin-prometheus.go b/cmd/admin-prometheus.go index c251d446..7c12ff78 100644 --- a/cmd/admin-prometheus.go +++ b/cmd/admin-prometheus.go @@ -18,6 +18,10 @@ package cmd import "github.com/minio/cli" +var adminPrometheusSubcommands = []cli.Command{ + adminPrometheusGenerateCmd, +} + var adminPrometheusCmd = cli.Command{ Name: "prometheus", Usage: "manages prometheus config", @@ -25,9 +29,7 @@ var adminPrometheusCmd = cli.Command{ Before: setGlobalsFromContext, Flags: globalFlags, HideHelpCommand: true, - Subcommands: []cli.Command{ - adminPrometheusGenerateCmd, - }, + Subcommands: adminPrometheusSubcommands, CustomHelpTemplate: `NAME: {{.HelpName}} - {{.Usage}} @@ -42,6 +44,6 @@ FLAGS: // mainAdminPrometheus is the handle for "mc admin prometheus" command. func mainAdminPrometheus(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminPrometheusSubcommands) return nil } diff --git a/cmd/admin-service.go b/cmd/admin-service.go index 5a82e76c..566ad29b 100644 --- a/cmd/admin-service.go +++ b/cmd/admin-service.go @@ -18,6 +18,11 @@ package cmd import "github.com/minio/cli" +var adminServiceSubcommands = []cli.Command{ + adminServiceRestartCmd, + adminServiceStopCmd, +} + var adminServiceCmd = cli.Command{ Name: "service", Usage: "restart and stop all MinIO servers", @@ -25,15 +30,12 @@ var adminServiceCmd = cli.Command{ Before: setGlobalsFromContext, Flags: globalFlags, HideHelpCommand: true, - Subcommands: []cli.Command{ - adminServiceRestartCmd, - adminServiceStopCmd, - }, + Subcommands: adminServiceSubcommands, } // mainAdmin is the handle for "mc admin service" command. func mainAdminService(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminServiceSubcommands) return nil // Sub-commands like "status", "restart" have their own main. } diff --git a/cmd/admin-top.go b/cmd/admin-top.go index 753fffe0..a46de162 100644 --- a/cmd/admin-top.go +++ b/cmd/admin-top.go @@ -18,21 +18,23 @@ package cmd import "github.com/minio/cli" +var adminTopSubcommands = []cli.Command{ + adminTopLocksCmd, +} + var adminTopCmd = cli.Command{ - Name: "top", - Usage: "provide top like statistics for MinIO", - Action: mainAdminTop, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - adminTopLocksCmd, - }, + Name: "top", + Usage: "provide top like statistics for MinIO", + Action: mainAdminTop, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: adminTopSubcommands, HideHelpCommand: true, } // mainAdminTop is the handle for "mc admin top" command. func mainAdminTop(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminTopSubcommands) return nil // Sub-commands like "locks" have their own main. } diff --git a/cmd/admin-user.go b/cmd/admin-user.go index b2d1c1b6..158cd088 100644 --- a/cmd/admin-user.go +++ b/cmd/admin-user.go @@ -18,26 +18,28 @@ package cmd import "github.com/minio/cli" +var adminUserSubcommands = []cli.Command{ + adminUserAddCmd, + adminUserDisableCmd, + adminUserEnableCmd, + adminUserRemoveCmd, + adminUserListCmd, + adminUserInfoCmd, +} + var adminUserCmd = cli.Command{ - Name: "user", - Usage: "manage users", - Action: mainAdminUser, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - adminUserAddCmd, - adminUserDisableCmd, - adminUserEnableCmd, - adminUserRemoveCmd, - adminUserListCmd, - adminUserInfoCmd, - }, + Name: "user", + Usage: "manage users", + Action: mainAdminUser, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: adminUserSubcommands, HideHelpCommand: true, } // mainAdminUser is the handle for "mc admin config" command. func mainAdminUser(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, adminUserSubcommands) return nil // Sub-commands like "get", "set" have their own main. } diff --git a/cmd/alias-main.go b/cmd/alias-main.go index af62f763..b016c717 100644 --- a/cmd/alias-main.go +++ b/cmd/alias-main.go @@ -38,6 +38,12 @@ var ( aliasFlags = []cli.Flag{} ) +var aliasSubcommands = []cli.Command{ + aliasSetCmd, + aliasListCmd, + aliasRemoveCmd, +} + var aliasCmd = cli.Command{ Name: "alias", Usage: "set, remove and list aliases in configuration file", @@ -45,16 +51,12 @@ var aliasCmd = cli.Command{ Before: setGlobalsFromContext, HideHelpCommand: true, Flags: append(aliasFlags, globalFlags...), - Subcommands: []cli.Command{ - aliasSetCmd, - aliasListCmd, - aliasRemoveCmd, - }, + Subcommands: aliasSubcommands, } // mainAlias is the handle for "mc alias" command. provides sub-commands which write configuration data in json format to config file. func mainAlias(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, aliasSubcommands) return nil // Sub-commands like add, list and remove have their own main. } diff --git a/cmd/encrypt-main.go b/cmd/encrypt-main.go index ee26f933..2c507cbf 100644 --- a/cmd/encrypt-main.go +++ b/cmd/encrypt-main.go @@ -18,6 +18,12 @@ package cmd import "github.com/minio/cli" +var encryptSubcommands = []cli.Command{ + encryptSetCmd, + encryptClearCmd, + encryptInfoCmd, +} + var encryptCmd = cli.Command{ Name: "encrypt", Usage: "manage bucket encryption config", @@ -25,16 +31,12 @@ var encryptCmd = cli.Command{ Action: mainEncrypt, Before: setGlobalsFromContext, Flags: globalFlags, - Subcommands: []cli.Command{ - encryptSetCmd, - encryptClearCmd, - encryptInfoCmd, - }, + Subcommands: encryptSubcommands, } // mainEncrypt is the handle for "mc encrypt" command. func mainEncrypt(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, encryptSubcommands) return nil // Sub-commands like "info", "set", "clear" have their own main. } diff --git a/cmd/event-main.go b/cmd/event-main.go index 13b93f8f..f4c36797 100644 --- a/cmd/event-main.go +++ b/cmd/event-main.go @@ -22,6 +22,12 @@ var ( eventFlags = []cli.Flag{} ) +var eventSubcommands = []cli.Command{ + eventAddCmd, + eventRemoveCmd, + eventListCmd, +} + var eventCmd = cli.Command{ Name: "event", Usage: "manage object notifications", @@ -29,16 +35,12 @@ var eventCmd = cli.Command{ Action: mainEvent, Before: setGlobalsFromContext, Flags: append(eventFlags, globalFlags...), - Subcommands: []cli.Command{ - eventAddCmd, - eventRemoveCmd, - eventListCmd, - }, + Subcommands: eventSubcommands, } // mainEvent is the handle for "mc event" command. func mainEvent(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, eventSubcommands) return nil // Sub-commands like "add", "remove", "list" have their own main. } diff --git a/cmd/flags.go b/cmd/flags.go index 1fc858c1..f597bb63 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -18,15 +18,8 @@ package cmd import ( "github.com/minio/cli" - "github.com/minio/minio/pkg/trie" ) -// Collection of mc commands currently supported -var commands = []cli.Command{} - -// Collection of mc commands currently supported in a trie tree -var commandsTree = trie.NewTrie() - // Collection of mc flags currently supported var globalFlags = []cli.Flag{ cli.StringFlag{ @@ -63,9 +56,3 @@ var ioFlags = []cli.Flag{ Usage: "encrypt/decrypt objects (using server-side encryption with customer provided keys)", }, } - -// registerCmd registers a cli command -func registerCmd(cmd cli.Command) { - commands = append(commands, cmd) - commandsTree.Insert(cmd.Name) -} diff --git a/cmd/ilm-main.go b/cmd/ilm-main.go index 6642d1ef..d166e137 100644 --- a/cmd/ilm-main.go +++ b/cmd/ilm-main.go @@ -22,21 +22,23 @@ import ( "github.com/minio/minio/pkg/console" ) -var bucketILMCmd = cli.Command{ +var ilmSubcommands = []cli.Command{ + ilmLsCmd, + ilmAddCmd, + ilmRmCmd, + ilmSetCmd, + ilmExportCmd, + ilmImportCmd, +} + +var ilmCmd = cli.Command{ Name: "ilm", Usage: "manage bucket lifecycle", Action: mainILM, Before: setGlobalsFromContext, Flags: globalFlags, HideHelpCommand: true, - Subcommands: []cli.Command{ - ilmLsCmd, - ilmAddCmd, - ilmRmCmd, - ilmSetCmd, - ilmExportCmd, - ilmImportCmd, - }, + Subcommands: ilmSubcommands, } const ( @@ -50,7 +52,7 @@ const ( ) func mainILM(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, ilmSubcommands) return nil } diff --git a/cmd/legalhold-main.go b/cmd/legalhold-main.go index 2e30de72..9619d48b 100644 --- a/cmd/legalhold-main.go +++ b/cmd/legalhold-main.go @@ -29,17 +29,19 @@ import ( "github.com/minio/minio/pkg/console" ) +var legalHoldSubcommands = []cli.Command{ + legalHoldSetCmd, + legalHoldClearCmd, + legalHoldInfoCmd, +} + var legalHoldCmd = cli.Command{ - Name: "legalhold", - Usage: "manage legal hold for object(s)", - Action: mainLegalHold, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - legalHoldSetCmd, - legalHoldClearCmd, - legalHoldInfoCmd, - }, + Name: "legalhold", + Usage: "manage legal hold for object(s)", + Action: mainLegalHold, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: legalHoldSubcommands, } // Structured message depending on the type of console. @@ -111,6 +113,6 @@ func getBucketLockStatus(ctx context.Context, aliasedURL string) (status string, // main for retention command. func mainLegalHold(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, legalHoldSubcommands) return nil } diff --git a/cmd/main.go b/cmd/main.go index e87171d4..8ec26156 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -32,6 +32,7 @@ import ( "github.com/minio/cli" "github.com/minio/mc/pkg/probe" "github.com/minio/minio/pkg/console" + "github.com/minio/minio/pkg/trie" "github.com/minio/minio/pkg/words" "github.com/pkg/profile" @@ -122,9 +123,18 @@ func Main(args []string) { } // Function invoked when invalid command is passed. -func commandNotFound(ctx *cli.Context, command string) { - msg := fmt.Sprintf("`%s` is not a mc command. See `mc --help`.", command) - closestCommands := findClosestCommands(command) +func commandNotFound(ctx *cli.Context, cmds []cli.Command) { + command := ctx.Args().First() + if command == "" { + cli.ShowCommandHelp(ctx, command) + return + } + msg := fmt.Sprintf("`%s` is not a recognized command. Get help using `--help` flag.", command) + var commandsTree = trie.NewTrie() + for _, cmd := range cmds { + commandsTree.Insert(cmd.Name) + } + closestCommands := findClosestCommands(commandsTree, command) if len(closestCommands) > 0 { msg += "\n\nDid you mean one of these?\n" if len(closestCommands) == 1 { @@ -280,7 +290,7 @@ func registerBefore(ctx *cli.Context) error { } // findClosestCommands to match a given string with commands trie tree. -func findClosestCommands(command string) []string { +func findClosestCommands(commandsTree *trie.Trie, command string) []string { closestCommands := commandsTree.PrefixMatch(command) sort.Strings(closestCommands) // Suggest other close commands - allow missed, wrongly added and even transposed characters @@ -337,7 +347,7 @@ var appCmds = []cli.Command{ diffCmd, rmCmd, versionCmd, - bucketILMCmd, + ilmCmd, encryptCmd, eventCmd, watchCmd, @@ -351,10 +361,6 @@ var appCmds = []cli.Command{ } func registerApp(name string) *cli.App { - for _, cmd := range appCmds { - registerCmd(cmd) - } - cli.HelpFlag = cli.BoolFlag{ Name: "help, h", Usage: "show help", @@ -374,7 +380,12 @@ func registerApp(name string) *cli.App { return nil } - cli.ShowAppHelp(ctx) + if ctx.Args().First() != "" { + commandNotFound(ctx, app.Commands) + } else { + cli.ShowAppHelp(ctx) + } + return exitStatus(globalErrorExitStatus) } @@ -388,12 +399,11 @@ func registerApp(name string) *cli.App { app.HideHelpCommand = true app.Usage = "MinIO Client for cloud storage and filesystems." - app.Commands = commands + app.Commands = appCmds app.Author = "MinIO, Inc." app.Version = ReleaseTag app.Flags = append(mcFlags, globalFlags...) app.CustomAppHelpTemplate = mcHelpTemplate - app.CommandNotFound = commandNotFound // handler function declared above. app.EnableBashCompletion = true return app diff --git a/cmd/replicate-main.go b/cmd/replicate-main.go index 9f17e819..0dc01272 100644 --- a/cmd/replicate-main.go +++ b/cmd/replicate-main.go @@ -18,6 +18,15 @@ package cmd import "github.com/minio/cli" +var replicateSubcommands = []cli.Command{ + replicateAddCmd, + replicateSetCmd, + replicateListCmd, + replicateExportCmd, + replicateImportCmd, + replicateRemoveCmd, +} + var replicateCmd = cli.Command{ Name: "replicate", Usage: "configure server side bucket replication", @@ -25,19 +34,12 @@ var replicateCmd = cli.Command{ Action: mainReplicate, Before: setGlobalsFromContext, Flags: globalFlags, - Subcommands: []cli.Command{ - replicateAddCmd, - replicateSetCmd, - replicateListCmd, - replicateExportCmd, - replicateImportCmd, - replicateRemoveCmd, - }, + Subcommands: replicateSubcommands, } // mainReplicate is the handle for "mc replicate" command. func mainReplicate(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, replicateSubcommands) return nil // Sub-commands like "list", "clear", "add" have their own main. } diff --git a/cmd/retention-main.go b/cmd/retention-main.go index 099f7a55..766e0741 100644 --- a/cmd/retention-main.go +++ b/cmd/retention-main.go @@ -20,21 +20,23 @@ import ( "github.com/minio/cli" ) +var retentionSubcommands = []cli.Command{ + retentionSetCmd, + retentionClearCmd, + retentionInfoCmd, +} + var retentionCmd = cli.Command{ - Name: "retention", - Usage: "set retention for object(s)", - Action: mainRetention, - Before: setGlobalsFromContext, - Flags: globalFlags, - Subcommands: []cli.Command{ - retentionSetCmd, - retentionClearCmd, - retentionInfoCmd, - }, + Name: "retention", + Usage: "set retention for object(s)", + Action: mainRetention, + Before: setGlobalsFromContext, + Flags: globalFlags, + Subcommands: retentionSubcommands, } // main for retention command. func mainRetention(ctx *cli.Context) error { - cli.ShowCommandHelpAndExit(ctx, ctx.Args().First(), 1) + commandNotFound(ctx, retentionSubcommands) return nil } diff --git a/cmd/share-main.go b/cmd/share-main.go index ec995f4f..18b53ae6 100644 --- a/cmd/share-main.go +++ b/cmd/share-main.go @@ -29,6 +29,12 @@ var ( shareFlags = []cli.Flag{} ) +var shareSubcommands = []cli.Command{ + shareDownload, + shareUpload, + shareList, +} + // Share documents via URL. var shareCmd = cli.Command{ Name: "share", @@ -37,11 +43,7 @@ var shareCmd = cli.Command{ Before: setGlobalsFromContext, Flags: append(shareFlags, globalFlags...), HideHelpCommand: true, - Subcommands: []cli.Command{ - shareDownload, - shareUpload, - shareList, - }, + Subcommands: shareSubcommands, } // migrateShare migrate to newest version sequentially. @@ -62,7 +64,7 @@ func migrateShare() { // mainShare - main handler for mc share command. func mainShare(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, shareSubcommands) return nil // Sub-commands like "upload" and "download" have their own main. } diff --git a/cmd/tag-main.go b/cmd/tag-main.go index 23745008..c66082f5 100644 --- a/cmd/tag-main.go +++ b/cmd/tag-main.go @@ -20,6 +20,12 @@ import ( "github.com/minio/cli" ) +var tagSubcommands = []cli.Command{ + tagListCmd, + tagRemoveCmd, + tagSetCmd, +} + var tagCmd = cli.Command{ Name: "tag", Usage: "manage tags for bucket and object(s)", @@ -27,14 +33,10 @@ var tagCmd = cli.Command{ Before: setGlobalsFromContext, Flags: globalFlags, HideHelpCommand: true, - Subcommands: []cli.Command{ - tagListCmd, - tagRemoveCmd, - tagSetCmd, - }, + Subcommands: tagSubcommands, } func mainTag(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, tagSubcommands) return nil } diff --git a/cmd/version-main.go b/cmd/version-main.go index d824d15c..c0c35684 100644 --- a/cmd/version-main.go +++ b/cmd/version-main.go @@ -18,6 +18,12 @@ package cmd import "github.com/minio/cli" +var versionSubcommands = []cli.Command{ + versionEnableCmd, + versionSuspendCmd, + versionInfoCmd, +} + var versionCmd = cli.Command{ Name: "version", Usage: "manage bucket versioning", @@ -25,16 +31,12 @@ var versionCmd = cli.Command{ Action: mainVersion, Before: setGlobalsFromContext, Flags: globalFlags, - Subcommands: []cli.Command{ - versionEnableCmd, - versionSuspendCmd, - versionInfoCmd, - }, + Subcommands: versionSubcommands, } // mainVersion is the handle for "mc version" command. func mainVersion(ctx *cli.Context) error { - cli.ShowCommandHelp(ctx, ctx.Args().First()) + commandNotFound(ctx, versionSubcommands) return nil // Sub-commands like "info", "enable", "suspend" have their own main. }