From 39f74417904ebca335da4ac55f20d5bf9603afdd Mon Sep 17 00:00:00 2001 From: "Anand Babu (AB) Periasamy" Date: Sun, 15 Nov 2015 20:05:58 -0800 Subject: [PATCH] fixes related to help handling --- config-main.go | 16 ++++++++++------ cp-main.go | 2 +- help-main.go | 10 ---------- ls-main.go | 8 ++++---- mirror-main.go | 8 ++++---- rm-main.go | 11 +++++------ session-main.go | 10 +++++----- share-main.go | 10 ++++++---- 8 files changed, 35 insertions(+), 40 deletions(-) diff --git a/config-main.go b/config-main.go index e5ea8894..047c0b15 100644 --- a/config-main.go +++ b/config-main.go @@ -30,7 +30,7 @@ import "github.com/minio/cli" // var configCmd = cli.Command{ Name: "config", - Usage: "Manage ‘mc’ configuration.", + Usage: "Manage configuration file.", Action: mainConfig, Subcommands: []cli.Command{ configAliasCmd, @@ -38,20 +38,24 @@ var configCmd = cli.Command{ configVersionCmd, }, CustomHelpTemplate: `NAME: - {{.Name}} - {{.Usage}} + mc {{.Name}} - {{.Usage}} USAGE: - {{.Name}} {{if .Flags}}[global flags] {{end}}command{{if .Flags}} [command flags]{{end}} [arguments...] + mc {{.Name}} COMMAND COMMANDS: - {{range .Commands}}{{ .Name }}{{ "\t" }}{{.Usage}} + {{range .Subcommands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} {{end}} `, } // 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() { - cli.ShowAppHelp(ctx) + if ctx.Args().First() != "" { // command help. + cli.ShowCommandHelp(ctx, ctx.Args().First()) + } else { // mc help. + cli.ShowSubcommandHelp(ctx) } + + // sub-commands like "upload" and "download" have their own main. } diff --git a/cp-main.go b/cp-main.go index 192b42bd..525589f1 100644 --- a/cp-main.go +++ b/cp-main.go @@ -43,7 +43,7 @@ var cpCmd = cli.Command{ mc {{.Name}} - {{.Usage}} USAGE: - mc {{.Name}} [OPTIONS] SOURCE [SOURCE...] TARGET + mc {{.Name}} SOURCE [SOURCE...] TARGET EXAMPLES: 1. Copy a list of objects from local file system to Amazon S3 cloud storage. diff --git a/help-main.go b/help-main.go index bac7d088..80a6538a 100644 --- a/help-main.go +++ b/help-main.go @@ -38,18 +38,8 @@ EXAMPLES: `, } -// 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. diff --git a/ls-main.go b/ls-main.go index 1588a509..032d3c96 100644 --- a/ls-main.go +++ b/ls-main.go @@ -43,11 +43,11 @@ var lsCmd = cli.Command{ mc {{.Name}} - {{.Usage}} USAGE: - mc {{.Name}} [OPTIONS] TARGET [TARGET ...] - -OPTIONS: - --incomplete - List incomplete upload of objects. + mc {{.Name}} [FLAGS] TARGET [TARGET ...] +FLAGS: + {{range .Flags}}{{.}} + {{end}} EXAMPLES: 1. List buckets on Amazon S3 cloud storage. $ mc {{.Name}} https://s3.amazonaws.com/ diff --git a/mirror-main.go b/mirror-main.go index 0fa918ce..88122bfa 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -51,11 +51,11 @@ var mirrorCmd = cli.Command{ mc {{.Name}} - {{.Usage}} USAGE: - mc {{.Name}} [OPTIONS] SOURCE TARGET [TARGET...] - -OPTIONS: - --force - Force overwrite of an existing target(s). + mc {{.Name}} [FLAGS] SOURCE TARGET [TARGET...] +FLAGS: + {{range .Flags}}{{.}} + {{end}} EXAMPLES: 1. Mirror a bucket recursively from Minio cloud storage to a bucket on Amazon S3 cloud storage. $ mc {{.Name}} https://play.minio.io:9000/photos/2014 https://s3.amazonaws.com/backup-photos diff --git a/rm-main.go b/rm-main.go index 0b15ca54..a575144c 100644 --- a/rm-main.go +++ b/rm-main.go @@ -37,7 +37,7 @@ var ( rmFlagIncomplete = cli.BoolFlag{ Name: "incomplete, I", - Usage: "remove incomplete uploads.", + Usage: "Remove an incomplete upload(s).", } ) @@ -51,12 +51,11 @@ var rmCmd = cli.Command{ mc {{.Name}} - {{.Usage}} USAGE: - mc {{.Name}} [OPTIONS] TARGET [TARGET ...] - -OPTIONS: - --force - Force a dangerous remove operation. - --incomplete - Remove incomplete uploads. + mc {{.Name}} [FLAGS] TARGET [TARGET ...] +FLAGS: + {{range .Flags}}{{.}} + {{end}} EXAMPLES: 1. Remove an object. $ mc {{.Name}} https://s3.amazonaws.com/jazz-songs/louis/file01.mp3 diff --git a/session-main.go b/session-main.go index 6750af86..09411fa6 100644 --- a/session-main.go +++ b/session-main.go @@ -41,17 +41,17 @@ USAGE: mc {{.Name}} resume SESSION-ID mc {{.Name}} clear SESSION-ID - SESSION-ID = $SESSION | all +SESSION-ID: + SESSION - Session can either be $SESSION-ID or "all". EXAMPLES: - 1. List sessions + 1. List sessions. $ mc {{.Name}} list - ygVIpSJs -> [2015-08-29 15:25:12 PDT] cp /usr/bin... test - 2. Resume session + 2. Resume session. $ mc {{.Name}} resume ygVIpSJs - 3. Clear session + 3. Clear session. $ mc {{.Name}} clear ygVIpSJs `, } diff --git a/share-main.go b/share-main.go index 5d68edec..da556a95 100644 --- a/share-main.go +++ b/share-main.go @@ -36,10 +36,10 @@ var shareCmd = cli.Command{ shareList, }, CustomHelpTemplate: `NAME: - {{.Name}} - {{.Usage}} + mc {{.Name}} - {{.Usage}} USAGE: - {{.Name}} command [arguments...] + mc {{.Name}} [COMMAND] COMMANDS: {{range .Subcommands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} @@ -65,8 +65,10 @@ func migrateShare() { // mainShare - main handler for mc share command func mainShare(ctx *cli.Context) { - if !ctx.Args().Present() || ctx.Args().First() == "help" { - cli.ShowAppHelp(ctx) + if ctx.Args().First() != "" { // command help. + cli.ShowCommandHelp(ctx, ctx.Args().First()) + } else { // mc help. + cli.ShowSubcommandHelp(ctx) } // sub-commands like "upload" and "download" have their own main.