Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/modelcmd: return ModelCommand from Wrap #7209

Merged
merged 1 commit into from Apr 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions cmd/modelcmd/modelcommand.go
Expand Up @@ -254,11 +254,11 @@ func wrapSkipDefaultModel(w *modelCommandWrapper) {
w.useDefaultModel = false
}

// Wrap wraps the specified ModelCommand, returning a Command
// Wrap wraps the specified ModelCommand, returning a ModelCommand
// that proxies to each of the ModelCommand methods.
// Any provided options are applied to the wrapped command
// before it is returned.
func Wrap(c ModelCommand, options ...WrapOption) cmd.Command {
func Wrap(c ModelCommand, options ...WrapOption) ModelCommand {
wrapper := &modelCommandWrapper{
ModelCommand: c,
skipModelFlags: false,
Expand All @@ -267,7 +267,21 @@ func Wrap(c ModelCommand, options ...WrapOption) cmd.Command {
for _, option := range options {
option(wrapper)
}
return WrapBase(wrapper)
// Define a new type so that we can embed the ModelCommand
// interface one level deeper than cmd.Command, so that
// we'll get the Command methods from WrapBase
// and all the ModelCommand methods not in cmd.Command
// from modelCommandWrapper.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's modelCommandWrapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the type we're using above that wraps c.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a little magical, but the comment helps.

type embed struct {
ModelCommand
}
return struct {
embed
cmd.Command
}{
Command: WrapBase(wrapper),
embed: embed{wrapper},
}
}

type modelCommandWrapper struct {
Expand Down