mirror of
https://github.com/minio/mc.git
synced 2025-11-12 01:02:26 +03:00
global flags are replaced with command speific flags, but still retain global behavior
This commit is contained in:
@@ -38,7 +38,7 @@ var accessCmd = cli.Command{
|
|||||||
Name: "access",
|
Name: "access",
|
||||||
Usage: "Manage bucket access permissions.",
|
Usage: "Manage bucket access permissions.",
|
||||||
Action: mainAccess,
|
Action: mainAccess,
|
||||||
Flags: []cli.Flag{accessFlagHelp},
|
Flags: append(globalFlags, accessFlagHelp),
|
||||||
CustomHelpTemplate: `Name:
|
CustomHelpTemplate: `Name:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ var catCmd = cli.Command{
|
|||||||
Name: "cat",
|
Name: "cat",
|
||||||
Usage: "Display contents of a file.",
|
Usage: "Display contents of a file.",
|
||||||
Action: mainCat,
|
Action: mainCat,
|
||||||
Flags: []cli.Flag{catFlagHelp},
|
Flags: append(globalFlags, catFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ var configAliasCmd = cli.Command{
|
|||||||
Name: "alias",
|
Name: "alias",
|
||||||
Usage: "List, modify and remove aliases in configuration file.",
|
Usage: "List, modify and remove aliases in configuration file.",
|
||||||
Action: mainConfigAlias,
|
Action: mainConfigAlias,
|
||||||
Flags: []cli.Flag{configAliasFlagHelp},
|
Flags: append(globalFlags, configAliasFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc config {{.Name}} - {{.Usage}}
|
mc config {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ var (
|
|||||||
var configHostCmd = cli.Command{
|
var configHostCmd = cli.Command{
|
||||||
Name: "host",
|
Name: "host",
|
||||||
Usage: "List, modify and remove hosts in configuration file.",
|
Usage: "List, modify and remove hosts in configuration file.",
|
||||||
Flags: []cli.Flag{configHostFlagHelp},
|
Flags: append(globalFlags, configHostFlagHelp),
|
||||||
Action: mainConfigHost,
|
Action: mainConfigHost,
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc config {{.Name}} - {{.Usage}}
|
mc config {{.Name}} - {{.Usage}}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ var configCmd = cli.Command{
|
|||||||
Name: "config",
|
Name: "config",
|
||||||
Usage: "Manage configuration file.",
|
Usage: "Manage configuration file.",
|
||||||
Action: mainConfig,
|
Action: mainConfig,
|
||||||
Flags: []cli.Flag{configFlagHelp},
|
Flags: append(globalFlags, configFlagHelp),
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
configAliasCmd,
|
configAliasCmd,
|
||||||
configHostCmd,
|
configHostCmd,
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ var configVersionCmd = cli.Command{
|
|||||||
Name: "version",
|
Name: "version",
|
||||||
Usage: "Print config version.",
|
Usage: "Print config version.",
|
||||||
Action: mainConfigVersion,
|
Action: mainConfigVersion,
|
||||||
Flags: []cli.Flag{configVersionFlagHelp},
|
Flags: append(globalFlags, configVersionFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc config {{.Name}} - {{.Usage}}
|
mc config {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ var cpCmd = cli.Command{
|
|||||||
Name: "cp",
|
Name: "cp",
|
||||||
Usage: "Copy one or more objects to a target.",
|
Usage: "Copy one or more objects to a target.",
|
||||||
Action: mainCopy,
|
Action: mainCopy,
|
||||||
Flags: []cli.Flag{cpFlagRecursive, cpFlagHelp},
|
Flags: append(globalFlags, cpFlagRecursive, cpFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ var diffCmd = cli.Command{
|
|||||||
Usage: "Compute differences between two folders.",
|
Usage: "Compute differences between two folders.",
|
||||||
Description: "Diff only lists missing objects or objects with size differences. It *DOES NOT* compare contents. i.e. Objects of same name and size, but differ in contents are not noticed.",
|
Description: "Diff only lists missing objects or objects with size differences. It *DOES NOT* compare contents. i.e. Objects of same name and size, but differ in contents are not noticed.",
|
||||||
Action: mainDiff,
|
Action: mainDiff,
|
||||||
Flags: []cli.Flag{diffFlagHelp},
|
Flags: append(globalFlags, diffFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
44
flags.go
44
flags.go
@@ -21,54 +21,36 @@ import "github.com/minio/cli"
|
|||||||
// Collection of mc commands currently supported
|
// Collection of mc commands currently supported
|
||||||
var commands = []cli.Command{}
|
var commands = []cli.Command{}
|
||||||
|
|
||||||
// Collection of mc flags currently supported
|
|
||||||
var flags = []cli.Flag{}
|
|
||||||
|
|
||||||
// Collection of mc commands currently supported in a trie tree
|
// Collection of mc commands currently supported in a trie tree
|
||||||
var commandsTree = newTrie()
|
var commandsTree = newTrie()
|
||||||
|
|
||||||
var (
|
// Collection of mc flags currently supported
|
||||||
helpFlag = cli.BoolFlag{
|
var globalFlags = []cli.Flag{
|
||||||
Name: "help, h",
|
cli.StringFlag{
|
||||||
Usage: "Help for mc.",
|
|
||||||
}
|
|
||||||
|
|
||||||
configFlag = cli.StringFlag{
|
|
||||||
Name: "config-folder, C",
|
Name: "config-folder, C",
|
||||||
Value: mustGetMcConfigDir(),
|
Value: mustGetMcConfigDir(),
|
||||||
Usage: "Path to configuration folder.",
|
Usage: "Path to configuration folder.",
|
||||||
}
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
quietFlag = cli.BoolFlag{
|
|
||||||
Name: "quiet, q",
|
Name: "quiet, q",
|
||||||
Usage: "Suppress chatty console output.",
|
Usage: "Suppress chatty console output.",
|
||||||
}
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
colorsFlag = cli.BoolFlag{
|
|
||||||
Name: "no-color",
|
Name: "no-color",
|
||||||
Usage: "Disable color theme.",
|
Usage: "Disable color theme.",
|
||||||
}
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
jsonFlag = cli.BoolFlag{
|
|
||||||
Name: "json",
|
Name: "json",
|
||||||
Usage: "Enable json formatted output.",
|
Usage: "Enable json formatted output.",
|
||||||
}
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
debugFlag = cli.BoolFlag{
|
|
||||||
Name: "debug",
|
Name: "debug",
|
||||||
Usage: "Enable debugging output.",
|
Usage: "Enable debugging output.",
|
||||||
}
|
},
|
||||||
|
}
|
||||||
// Add your new flags starting here
|
|
||||||
)
|
|
||||||
|
|
||||||
// registerCmd registers a cli command
|
// registerCmd registers a cli command
|
||||||
func registerCmd(cmd cli.Command) {
|
func registerCmd(cmd cli.Command) {
|
||||||
commands = append(commands, cmd)
|
commands = append(commands, cmd)
|
||||||
commandsTree.Insert(cmd.Name)
|
commandsTree.Insert(cmd.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerFlag registers a cli flag
|
|
||||||
func registerFlag(flag cli.Flag) {
|
|
||||||
flags = append(flags, flag)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ var lsCmd = cli.Command{
|
|||||||
Name: "ls",
|
Name: "ls",
|
||||||
Usage: "List files and folders.",
|
Usage: "List files and folders.",
|
||||||
Action: mainList,
|
Action: mainList,
|
||||||
Flags: []cli.Flag{lsFlagRecursive, lsFlagIncomplete, lsFlagHelp},
|
Flags: append(globalFlags, lsFlagRecursive, lsFlagIncomplete, lsFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
15
main.go
15
main.go
@@ -110,12 +110,6 @@ func getSystemData() map[string]string {
|
|||||||
func registerBefore(ctx *cli.Context) error {
|
func registerBefore(ctx *cli.Context) error {
|
||||||
setMcConfigDir(ctx.GlobalString("config-folder"))
|
setMcConfigDir(ctx.GlobalString("config-folder"))
|
||||||
|
|
||||||
// Set global states from global flags.
|
|
||||||
setGlobals(ctx.GlobalBool("quiet"),
|
|
||||||
ctx.GlobalBool("debug"),
|
|
||||||
ctx.GlobalBool("json"),
|
|
||||||
ctx.GlobalBool("no-color"))
|
|
||||||
|
|
||||||
// Verify golang runtime.
|
// Verify golang runtime.
|
||||||
verifyMCRuntime()
|
verifyMCRuntime()
|
||||||
|
|
||||||
@@ -155,18 +149,9 @@ func registerApp() *cli.App {
|
|||||||
registerCmd(updateCmd) // Check for new software updates.
|
registerCmd(updateCmd) // Check for new software updates.
|
||||||
registerCmd(versionCmd) // Print version.
|
registerCmd(versionCmd) // Print version.
|
||||||
|
|
||||||
// register all the flags (refer flags.go)
|
|
||||||
registerFlag(helpFlag) // Show help.
|
|
||||||
registerFlag(configFlag) // Path to configuration folder.
|
|
||||||
registerFlag(quietFlag) // Suppress chatty console output.
|
|
||||||
registerFlag(jsonFlag) // Enable json formatted output.
|
|
||||||
registerFlag(debugFlag) // Enable debugging output.
|
|
||||||
registerFlag(colorsFlag) // Choose different styles of console coloring.
|
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Usage = "Minio Client for cloud storage and filesystems."
|
app.Usage = "Minio Client for cloud storage and filesystems."
|
||||||
app.Commands = commands
|
app.Commands = commands
|
||||||
app.Flags = flags
|
|
||||||
app.Author = "Minio.io"
|
app.Author = "Minio.io"
|
||||||
app.CustomAppHelpTemplate = mcHelpTemplate
|
app.CustomAppHelpTemplate = mcHelpTemplate
|
||||||
app.CommandNotFound = commandNotFound // handler function declared above.
|
app.CommandNotFound = commandNotFound // handler function declared above.
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ var mbCmd = cli.Command{
|
|||||||
Name: "mb",
|
Name: "mb",
|
||||||
Usage: "Make a bucket or folder.",
|
Usage: "Make a bucket or folder.",
|
||||||
Action: mainMakeBucket,
|
Action: mainMakeBucket,
|
||||||
Flags: []cli.Flag{mbFlagHelp},
|
Flags: append(globalFlags, mbFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ var mirrorCmd = cli.Command{
|
|||||||
Name: "mirror",
|
Name: "mirror",
|
||||||
Usage: "Mirror folders recursively from a single source to many destinations.",
|
Usage: "Mirror folders recursively from a single source to many destinations.",
|
||||||
Action: mainMirror,
|
Action: mainMirror,
|
||||||
Flags: []cli.Flag{mirrorFlagForce, mirrorFlagHelp},
|
Flags: append(globalFlags, mirrorFlagForce, mirrorFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ var pipeCmd = cli.Command{
|
|||||||
Name: "pipe",
|
Name: "pipe",
|
||||||
Usage: "Write contents of stdin to one or more targets. When no target is specified, it writes to stdout.",
|
Usage: "Write contents of stdin to one or more targets. When no target is specified, it writes to stdout.",
|
||||||
Action: mainPipe,
|
Action: mainPipe,
|
||||||
Flags: []cli.Flag{pipeFlagHelp},
|
Flags: append(globalFlags, pipeFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -56,13 +56,7 @@ var rmCmd = cli.Command{
|
|||||||
Name: "rm",
|
Name: "rm",
|
||||||
Usage: "Remove file or bucket [WARNING: Use with care].",
|
Usage: "Remove file or bucket [WARNING: Use with care].",
|
||||||
Action: mainRm,
|
Action: mainRm,
|
||||||
Flags: []cli.Flag{
|
Flags: append(globalFlags, rmFlagRecursive, rmFlagForce, rmFlagIncomplete, rmFlagFake, rmFlagHelp),
|
||||||
rmFlagRecursive,
|
|
||||||
rmFlagForce,
|
|
||||||
rmFlagIncomplete,
|
|
||||||
rmFlagFake,
|
|
||||||
rmFlagHelp,
|
|
||||||
},
|
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ var sessionCmd = cli.Command{
|
|||||||
Name: "session",
|
Name: "session",
|
||||||
Usage: "Manage saved sessions of cp and mirror operations.",
|
Usage: "Manage saved sessions of cp and mirror operations.",
|
||||||
Action: mainSession,
|
Action: mainSession,
|
||||||
Flags: []cli.Flag{sessionFlagHelp},
|
Flags: append(globalFlags, sessionFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ var shareDownload = cli.Command{
|
|||||||
Name: "download",
|
Name: "download",
|
||||||
Usage: "Generate URLs for download access.",
|
Usage: "Generate URLs for download access.",
|
||||||
Action: mainShareDownload,
|
Action: mainShareDownload,
|
||||||
Flags: []cli.Flag{shareFlagRecursive, shareFlagExpire, shareFlagDownloadHelp},
|
Flags: append(globalFlags, shareFlagRecursive, shareFlagExpire, shareFlagDownloadHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc share {{.Name}} - {{.Usage}}
|
mc share {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ var shareList = cli.Command{
|
|||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "List previously shared objects and folders.",
|
Usage: "List previously shared objects and folders.",
|
||||||
Action: mainShareList,
|
Action: mainShareList,
|
||||||
Flags: []cli.Flag{shareFlagListHelp},
|
Flags: append(globalFlags, shareFlagListHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc share {{.Name}} COMMAND - {{.Usage}}
|
mc share {{.Name}} COMMAND - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ var shareCmd = cli.Command{
|
|||||||
Name: "share",
|
Name: "share",
|
||||||
Usage: "Generate URL for sharing.",
|
Usage: "Generate URL for sharing.",
|
||||||
Action: mainShare,
|
Action: mainShare,
|
||||||
Flags: []cli.Flag{shareFlagHelp},
|
Flags: append(globalFlags, shareFlagHelp),
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
shareDownload,
|
shareDownload,
|
||||||
shareUpload,
|
shareUpload,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ var shareUpload = cli.Command{
|
|||||||
Name: "upload",
|
Name: "upload",
|
||||||
Usage: "Generate ‘curl’ command to upload objects without requiring access/secret keys.",
|
Usage: "Generate ‘curl’ command to upload objects without requiring access/secret keys.",
|
||||||
Action: mainShareUpload,
|
Action: mainShareUpload,
|
||||||
Flags: []cli.Flag{shareFlagExpire, shareFlagContentType, shareFlagUploadHelp},
|
Flags: append(globalFlags, shareFlagExpire, shareFlagContentType, shareFlagUploadHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc share {{.Name}} - {{.Usage}}
|
mc share {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ var updateCmd = cli.Command{
|
|||||||
Name: "update",
|
Name: "update",
|
||||||
Usage: "Check for a new software update.",
|
Usage: "Check for a new software update.",
|
||||||
Action: mainUpdate,
|
Action: mainUpdate,
|
||||||
Flags: []cli.Flag{updateFlagExperimental, updateFlagHelp},
|
Flags: append(globalFlags, updateFlagExperimental, updateFlagHelp),
|
||||||
CustomHelpTemplate: `Name:
|
CustomHelpTemplate: `Name:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ var versionCmd = cli.Command{
|
|||||||
Name: "version",
|
Name: "version",
|
||||||
Usage: "Print version.",
|
Usage: "Print version.",
|
||||||
Action: mainVersion,
|
Action: mainVersion,
|
||||||
Flags: []cli.Flag{versionFlagHelp},
|
Flags: append(globalFlags, versionFlagHelp),
|
||||||
CustomHelpTemplate: `NAME:
|
CustomHelpTemplate: `NAME:
|
||||||
mc {{.Name}} - {{.Usage}}
|
mc {{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user