Allow specifying parent options after subcommands

Issue #141.
diff --git a/command_private.go b/command_private.go
index 5d30a8a..82ce793 100644
--- a/command_private.go
+++ b/command_private.go
@@ -144,6 +144,25 @@
 		commands:   make(map[string]*Command),
 	}
 
+	parent := c.parent
+
+	for parent != nil {
+		if cmd, ok := parent.(*Command); ok {
+			cmd.fillLookup(&ret, true)
+		}
+
+		if grp, ok := parent.(*Group); ok {
+			parent = grp
+		} else {
+			parent = nil
+		}
+	}
+
+	c.fillLookup(&ret, false)
+	return ret
+}
+
+func (c *Command) fillLookup(ret *lookup, onlyOptions bool) {
 	c.eachGroup(func(g *Group) {
 		for _, option := range g.options {
 			if option.ShortName != 0 {
@@ -156,6 +175,10 @@
 		}
 	})
 
+	if onlyOptions {
+		return
+	}
+
 	for _, subcommand := range c.commands {
 		ret.commands[subcommand.Name] = subcommand
 
@@ -163,8 +186,6 @@
 			ret.commands[a] = subcommand
 		}
 	}
-
-	return ret
 }
 
 func (c *Command) groupByName(name string) *Group {
diff --git a/command_test.go b/command_test.go
index a093e15..1d904ae 100644
--- a/command_test.go
+++ b/command_test.go
@@ -95,7 +95,55 @@
 		} `command:"cmd"`
 	}{}
 
-	assertParseFail(t, ErrUnknownFlag, "unknown flag `v'", &opts, "cmd", "-v", "-g")
+	assertParseSuccess(t, &opts, "cmd", "-v", "-g")
+
+	if !opts.Value {
+		t.Errorf("Expected Value to be true")
+	}
+
+	if !opts.Command.G {
+		t.Errorf("Expected Command.G to be true")
+	}
+}
+
+func TestCommandFlagOverride1(t *testing.T) {
+	var opts = struct {
+		Value bool `short:"v"`
+
+		Command struct {
+			Value bool `short:"v"`
+		} `command:"cmd"`
+	}{}
+
+	assertParseSuccess(t, &opts, "-v", "cmd")
+
+	if !opts.Value {
+		t.Errorf("Expected Value to be true")
+	}
+
+	if opts.Command.Value {
+		t.Errorf("Expected Command.Value to be false")
+	}
+}
+
+func TestCommandFlagOverride2(t *testing.T) {
+	var opts = struct {
+		Value bool `short:"v"`
+
+		Command struct {
+			Value bool `short:"v"`
+		} `command:"cmd"`
+	}{}
+
+	assertParseSuccess(t, &opts, "cmd", "-v")
+
+	if opts.Value {
+		t.Errorf("Expected Value to be false")
+	}
+
+	if !opts.Command.Value {
+		t.Errorf("Expected Command.Value to be true")
+	}
 }
 
 func TestCommandEstimate(t *testing.T) {
diff --git a/flags.go b/flags.go
index 37d331d..4ac6793 100644
--- a/flags.go
+++ b/flags.go
@@ -183,12 +183,16 @@
 remaining command line arguments.
 
 Command structs can have options which become valid to parse after the
-command has been specified on the command line. It is currently not valid
-to specify options from the parent level of the command after the command
-name has occurred. Thus, given a top-level option "-v" and a command "add":
+command has been specified on the command line, in addition to the options
+of all the parent commands. I.e. considering a -v flag on the parser and an
+add command, the following are equivalent:
 
-    Valid:   ./app -v add
-    Invalid: ./app add -v
+    ./app -v add
+    ./app add -v
+
+However, if the -v flag is defined on the add command, then the first of
+the two examples above would fail since the -v flag is not defined before
+the add command.
 
 
 Completion