Permalink
Browse files

tmp

  • Loading branch information...
1 parent dac5ed4 commit 29b9b06b353d6bc95ae79eb2085572fdf4e68bdb Daniel Bornkessel committed Mar 19, 2012
@@ -9,26 +9,37 @@ import (
//"os"
//"path/filepath"
//"sort"
- "fmt"
+ //"fmt"
)
-type SubSubCommandOptions map[string]SubCommandOptions
+type Scopes map[string]SubCommandOptions
-func (ssco SubCommandOptions) flattenToSubcommandOptions(subCommand string) (sco SubCommandOptions, err *GetOptError) {
- genericOptions := ssco["*"]
+type SubSubCommandOptions struct{
+ Global Option
+ Scopes Scopes
+}
+
+func (ssco SubSubCommandOptions) flattenToSubcommandOptions(subCommand string) (sco SubCommandOptions, err *GetOptError) {
+ genericOptions := ssco.Global
+
+ if subSubCommandOptions, present := ssco.Scopes[subCommand]; present == true {
- if subCommandOptions, present := ssco[subCommand]; present == true {
if subCommand != "*" {
- fmt.Printf("%#v", subCommandOptions)
- //subCommandOptions["*"] = append(subCommandOptions["*"], ssco["*"]...)
+ for _, option := range genericOptions.Definitions {
+ options.Definitions = append(options.Definitions, option)
+ }
+ }
+
+ for _, option := range subCommandOptions.Definitions {
+ options.Definitions = append(options.Definitions, option)
+ options.Description = subCommandOptions.Description
}
} else {
err = &GetOptError{UnknownSubcommand, "Unknown command: " + subCommand}
}
return
}
-
//func (sco SubCommandOptions) findSubcommand() (subCommand string, err *GetOptError) {
// options := sco["*"]
// subCommand = "*"
@@ -26,41 +26,67 @@ loopend:
}
func TestSubSubcommandOptionsConverter(t *testing.T) {
- ssco := SubSubCommandOptions{
- "*": {
- {"config|c", "config file", IsConfigFile | ExampleIsDefault, "/etc/visor.conf"},
- {"server|s", "doozer server", Optional, ""},
- {"scope", "scope", IsSubcommand, ""}},
-
- "app": {
- "*": {
- {"command", "command to execute", IsSubcommand, ""},
- {"foo|f", "a param", Optional, ""}},
- "getenv": {
- {"name", "app's name", IsArg | Required, ""},
- {"key", "environment variable's name", IsArg | Required, ""}},
- },
-
- "revision": {
- "*": {
- {"command", "command to execute", IsSubcommand, ""}},
- "list": {
- {"app|n", "app's name", IsArg | Required, ""}},
- },
- }
+ ssco := SubSubCommandOptions{
+ Global{
+ "global description",
+ Definitions{
+ {"config|c", "config file", IsConfigFile | ExampleIsDefault, "/etc/visor.conf"},
+ {"server|s", "doozer server", Optional, ""},
+ {"scope", "scope", IsSubcommand, ""},
+ },
+ },
+ Scopes{
+ "app": {
+ Global{
+ "app description",
+ {"command", "command to execute", IsSubcommand, ""},
+ {"foo|f", "a param", Optional, ""},
+ },
+ SubCommands{
+ "getenv": {
+ "app getenv description",
+ Definitions{
+ {"name", "app's name", IsArg | Required, ""},
+ {"key", "environment variable's name", IsArg | Required, ""},
+ },
+ },
+ "revision": {
+ "app revision description",
+ Definitions{
+ {"rev|r", "revision", IsArg | Required, ""},
+ },
+ },
+ },
+ },
+ },
+ }
- expectedAppSubOptions := SubCommandOptions{
- "*": {
- {"config|c", "config file", IsConfigFile | ExampleIsDefault, "/etc/visor.conf"},
- {"server|s", "doozer server", Optional, ""},
- {"scope", "scope", IsSubcommand, ""},
- {"command", "command to execute", IsSubcommand, ""}},
- "describe": {
- {"name|n", "app's name", IsArg | Required, ""}},
- "getenv": {
- {"name", "app's name", IsArg | Required, ""},
- {"key", "environment variable's name", IsArg | Required, ""}},
- }
+ expectedAppSubOptions := SubCommandOptions{
+ Global{
+ "app description",
+ Definitions{
+ {"config|c", "config file", IsConfigFile | ExampleIsDefault, "/etc/visor.conf"},
+ {"server|s", "doozer server", Optional, ""},
+ {"scope", "scope", IsSubcommand, ""},
+ {"command", "command to execute", IsSubcommand, ""},
+ },
+ },
+ SubCommands{
+ "getenv": {
+ "app getenv description",
+ Definitions{
+ {"name", "app's name", IsArg | Required, ""},
+ {"key", "environment variable's name", IsArg | Required, ""},
+ },
+ },
+ "revision": {
+ "app revision description",
+ Definitions{
+ {"rev|r", "revision", IsArg | Required, ""},
+ },
+ },
+ },
+ }
expectedRevisionOptions := Options{
"*": {

0 comments on commit 29b9b06

Please sign in to comment.