From d98b419a6a22cbc92b05cceac4e0ba7a23f604f3 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 31 May 2015 02:01:02 -0700 Subject: [PATCH] Why only modularize cmd, do flags as well --- cmd-options.go | 88 ++++++++++++++++++++++++-------------------------- main.go | 8 +++++ 2 files changed, 50 insertions(+), 46 deletions(-) diff --git a/cmd-options.go b/cmd-options.go index 0fe64320..3f26148b 100644 --- a/cmd-options.go +++ b/cmd-options.go @@ -27,58 +27,54 @@ import ( // Collection of mc commands currently supported are var commands = []cli.Command{} -/* -{ - mbCmd, // make a bucket - catCmd, // concantenate an object to standard output - cpCmd, // copy objects and files from multiple sources to single destination - syncCmd, // copy objects and files from single source to multiple destionations - diffCmd, // compare two objects - accessCmd, // set permissions [public, private, readonly, authenticated] for buckets and folders. - configCmd, // generate configuration "/home/harsha/.mc/config.json" file. - updateCmd, // update Check for new software updates - // Add your new commands starting from here -} -*/ - // Collection of mc flags currently supported +var flags = []cli.Flag{} + var ( - flags = []cli.Flag{ - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Supress chatty console output", - }, - cli.BoolFlag{ - Name: "alias", - Usage: "Mimic operating system toolchain behavior wherever it makes sense", - }, - cli.StringFlag{ - Name: "theme", - Value: console.GetDefaultThemeName(), - Usage: fmt.Sprintf("Choose a console theme from this list [%s]", func() string { - keys := []string{} - for _, themeName := range console.GetThemeNames() { - if console.GetThemeName() == themeName { - themeName = "*" + themeName + "*" - } - keys = append(keys, themeName) - } - return strings.Join(keys, ", ") - }()), - }, - cli.BoolFlag{ - Name: "json", - Usage: "Enable json formatted output", - }, - cli.BoolFlag{ - Name: "debug", - Usage: "Enable HTTP tracing", - }, - // Add your new flags starting here + quietFlag = cli.BoolFlag{ + Name: "quiet, q", + Usage: "Suppress chatty console output", } + + aliasFlag = cli.BoolFlag{ + Name: "alias", + Usage: "Mimic operating system toolchain behavior wherever it makes sense", + } + + themeFlag = cli.StringFlag{ + Name: "theme", + Value: console.GetDefaultThemeName(), + Usage: fmt.Sprintf("Choose a console theme from this list [%s]", func() string { + keys := []string{} + for _, themeName := range console.GetThemeNames() { + if console.GetThemeName() == themeName { + themeName = "*" + themeName + "*" + } + keys = append(keys, themeName) + } + return strings.Join(keys, ", ") + }()), + } + + jsonFlag = cli.BoolFlag{ + Name: "json", + Usage: "Enable json formatted output", + } + + debugFlag = cli.BoolFlag{ + Name: "debug", + Usage: "Enable debugging output", + } + + // Add your new flags starting here ) // registerCommand registers a cli command func registerCommand(cmd cli.Command) { commands = append(commands, cmd) } + +// registerFlag registers a cli flag +func registerFlag(flag cli.Flag) { + flags = append(flags, flag) +} diff --git a/main.go b/main.go index 473e1073..47be0ccf 100644 --- a/main.go +++ b/main.go @@ -98,6 +98,7 @@ func getSystemData() map[string]string { var Version = mustHashBinarySelf() func main() { + // register all the commands registerCommand(lsCmd) // List contents of a bucket registerCommand(mbCmd) // make a bucket registerCommand(catCmd) // concantenate an object to standard output @@ -108,6 +109,13 @@ func main() { registerCommand(configCmd) // generate configuration "/home/harsha/.mc/config.json" file. registerCommand(updateCmd) // update Check for new software updates + // register all the flags + registerFlag(quietFlag) // suppress console output + registerFlag(aliasFlag) // OS toolchain mimic + registerFlag(themeFlag) // console theme flag + registerFlag(jsonFlag) // json formatted output + registerFlag(debugFlag) // enable debugging output + app := cli.NewApp() app.Usage = "Minio Client for object storage and filesystems" app.Version = Version