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

Remove plugin wrapper. #17

Merged
1 commit merged into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
package cmd

import (
"fmt"

"github.com/juju/cmd"
"github.com/juju/gnuflag"

"github.com/juju/terms-client/api"
)

Expand All @@ -17,41 +12,3 @@ var (
return api.NewClient(options...)
}
)

type commandWithDescription interface {
cmd.Command
Description() string
}

// WrapPlugin returns a wrapped plugin command.
func WrapPlugin(cmd commandWithDescription) cmd.Command {
return &pluginWrapper{commandWithDescription: cmd}
}

type pluginWrapper struct {
commandWithDescription
Description bool
}

// SetFlags implements Command.SetFlags.
func (c *pluginWrapper) SetFlags(f *gnuflag.FlagSet) {
c.commandWithDescription.SetFlags(f)
f.BoolVar(&c.Description, "description", false, "returns command description")
}

// Init implements Command.Init.
func (c *pluginWrapper) Init(args []string) error {
if c.Description {
return nil
}
return c.commandWithDescription.Init(args)
}

// Run implements Command.Run.
func (c *pluginWrapper) Run(ctx *cmd.Context) error {
if c.Description {
fmt.Fprint(ctx.Stdout, c.commandWithDescription.Description())
return nil
}
return c.commandWithDescription.Run(ctx)
}
2 changes: 1 addition & 1 deletion cmd/list_terms.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ list-terms --groups test-group1,test-group2
// NewListTermsCommand returns a new command that can be used
// to list owned Terms and Conditions documents.
func NewListTermsCommand() cmd.Command {
return WrapPlugin(&listTermsCommand{})
return &listTermsCommand{}
}

type listTermsCommand struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/publish_term.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const publishTermPurpose = "releases the given terms document"
// used to publish existing owner terms
// Conditions documents.
func NewReleaseTermCommand() cmd.Command {
return WrapPlugin(&releaseTermCommand{})
return &releaseTermCommand{}
}

type releaseTermCommand struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/push_term.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const pushTermPurpose = "create new Terms and Conditions document (revision)"
// used to create new (revisions) of Terms and
// Conditions documents.
func NewPushTermCommand() cmd.Command {
return WrapPlugin(&pushTermCommand{})
return &pushTermCommand{}
}

// pushTermCommand creates a new Terms and Conditions document.
Expand Down
2 changes: 1 addition & 1 deletion cmd/show_term.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const showTermPurpose = "shows the specified term"
// NewShowTermCommand returns a new command that can be used
// to shows Terms and Conditions document.
func NewShowTermCommand() cmd.Command {
return WrapPlugin(&showTermCommand{})
return &showTermCommand{}
}

type showTermCommand struct {
Expand Down