-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jwaldrip/inherited-flags
Inherited flags
- Loading branch information
Showing
14 changed files
with
327 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
github.com/onsi/ginkgo | ||
github.com/onsi/gomega | ||
github.com/mattn/goveralls | ||
code.google.com/p/go.tools/cmd/cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
code.google.com/p/go-uuid #7dda39b2e7d5e265014674c5af696ba4186679e9 | ||
code.google.com/p/go.net #9cbdc6102a92af1201a1dbe68587693f2684e8a1 | ||
code.google.com/p/go.tools/cmd/cover #a9cbf58422bba01fd4a6c6db5c95530003e31c3a | ||
code.google.com/p/goauth2 #afe77d958c701557ec5dc56f6936fcc194d15520 | ||
code.google.com/p/google-api-go-client #11626ef0c2fd66fd8c9a128f6ae38b77cd101f30 | ||
github.com/mattn/goveralls #89ffc28b5e4c741a73c4ce4dd63dcf5695ca627d | ||
github.com/onsi/ginkgo #6bd31378f9b5c099a60ab96b89f8fa9b48678d44 | ||
github.com/onsi/gomega #a0ee4df1f2d58a75dd9d74e755615706d68e9ce9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
test: install-deps | ||
test: | ||
@clear | ||
goop exec sh -c "cd cli && go test" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cli | ||
|
||
// InheritFlags allow flag values inherit from the commands parent | ||
func (cmd *CLI) InheritFlags(names ...string) { | ||
for _, name := range names { | ||
cmd.InheritFlag(name) | ||
} | ||
} | ||
|
||
// InheritFlag allows a flags value to inherit from the commands parent | ||
func (cmd *CLI) InheritFlag(name string) { | ||
if cmd.parent == nil { | ||
panic("command does not have a parent") | ||
} | ||
flag := cmd.parent.(*CLI).getFlag(name) | ||
if cmd.inheritedFlags == nil { | ||
cmd.inheritedFlags = make(flagMap) | ||
} | ||
cmd.inheritedFlags[name] = flag | ||
} | ||
|
||
func (cmd *CLI) setFlagValuesFromParent() { | ||
for name, flag := range cmd.inheritedFlags { | ||
if _, exist := cmd.flags[name]; !exist { | ||
cmd.flagValues[flag] = cmd.parent.Flag(name) | ||
} | ||
} | ||
} | ||
|
||
// SubCommandsInheritFlags tells all subcommands to inherit flags | ||
func (cmd *CLI) SubCommandsInheritFlags(names ...string) { | ||
for _, name := range names { | ||
cmd.SubCommandsInheritFlag(name) | ||
} | ||
} | ||
|
||
// SubCommandsInheritFlag tells all subcommands to inherit a flag | ||
func (cmd *CLI) SubCommandsInheritFlag(name string) { | ||
flag := cmd.getFlag(name) | ||
if cmd.propogatingFlags == nil { | ||
cmd.propogatingFlags = make(flagMap) | ||
} | ||
cmd.propogatingFlags[name] = flag | ||
} | ||
|
||
func (cmd *CLI) copyPropogatingFlags() { | ||
if cmd.parent == nil { | ||
return | ||
} | ||
parentPropogatingFlags := cmd.parent.(*CLI).propogatingFlags | ||
cmd.propogatingFlags = parentPropogatingFlags.Without(cmd.flags).Merge(cmd.propogatingFlags) | ||
cmd.InheritFlags(parentPropogatingFlags.Names()...) | ||
} |
Oops, something went wrong.