github.com/LukasHeimann/cloudfoundrycli@v7.1.0+incompatible/plugin/rpc/fakecommand/fake_command2.go (about)

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