github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/plugin/rpc/fakecommand/fake_command1.go (about)

     1  package fakecommand
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/cf/commandregistry"
     7  	"code.cloudfoundry.org/cli/cf/flags"
     8  	"code.cloudfoundry.org/cli/cf/requirements"
     9  	"code.cloudfoundry.org/cli/cf/terminal"
    10  )
    11  
    12  type FakeCommand1 struct {
    13  	Data string
    14  	req  fakeReq
    15  	ui   terminal.UI
    16  }
    17  
    18  func init() {
    19  	commandregistry.Register(FakeCommand1{Data: "FakeCommand1 data", req: fakeReq{ui: nil}})
    20  }
    21  
    22  func (cmd FakeCommand1) MetaData() commandregistry.CommandMetadata {
    23  	return commandregistry.CommandMetadata{
    24  		Name:        "fake-command",
    25  		Description: "Description for fake-command",
    26  		Usage: []string{
    27  			"Usage of fake-command",
    28  		},
    29  	}
    30  }
    31  
    32  func (cmd FakeCommand1) Requirements(_ requirements.Factory, _ flags.FlagContext) ([]requirements.Requirement, error) {
    33  	reqs := []requirements.Requirement{cmd.req}
    34  	return reqs, nil
    35  }
    36  
    37  func (cmd FakeCommand1) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command {
    38  	if cmd.ui != nil {
    39  		cmd.ui.Say("SetDependency() called, pluginCall " + fmt.Sprintf("%t", pluginCall))
    40  	}
    41  
    42  	cmd.req.ui = deps.UI
    43  	cmd.ui = deps.UI
    44  
    45  	return cmd
    46  }
    47  
    48  func (cmd FakeCommand1) Execute(c flags.FlagContext) error {
    49  	cmd.ui.Say("Command Executed")
    50  	return nil
    51  }
    52  
    53  type fakeReq struct {
    54  	ui terminal.UI
    55  }
    56  
    57  func (f fakeReq) Execute() error {
    58  	f.ui.Say("Requirement executed")
    59  	return nil
    60  }