github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/requirements/factory.go (about)

     1  package requirements
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf"
     5  	"code.cloudfoundry.org/cli/cf/api"
     6  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     7  	. "code.cloudfoundry.org/cli/cf/i18n"
     8  	"github.com/blang/semver"
     9  )
    10  
    11  //go:generate counterfeiter . Factory
    12  
    13  type Factory interface {
    14  	NewApplicationRequirement(name string) ApplicationRequirement
    15  	NewDEAApplicationRequirement(name string) DEAApplicationRequirement
    16  	NewDiegoApplicationRequirement(name string) DiegoApplicationRequirement
    17  	NewServiceInstanceRequirement(name string) ServiceInstanceRequirement
    18  	NewLoginRequirement() Requirement
    19  	NewRoutingAPIRequirement() Requirement
    20  	NewSpaceRequirement(name string) SpaceRequirement
    21  	NewTargetedSpaceRequirement() Requirement
    22  	NewTargetedOrgRequirement() TargetedOrgRequirement
    23  	NewOrganizationRequirement(name string) OrganizationRequirement
    24  	NewDomainRequirement(name string) DomainRequirement
    25  	NewUserRequirement(username string, wantGUID bool) UserRequirement
    26  	NewBuildpackRequirement(buildpack string) BuildpackRequirement
    27  	NewAPIEndpointRequirement() Requirement
    28  	NewMinAPIVersionRequirement(commandName string, requiredVersion semver.Version) Requirement
    29  	NewMaxAPIVersionRequirement(commandName string, maximumVersion semver.Version) Requirement
    30  	NewUsageRequirement(Usable, string, func() bool) Requirement
    31  	NewNumberArguments([]string, ...string) Requirement
    32  }
    33  
    34  type apiRequirementFactory struct {
    35  	config      coreconfig.ReadWriter
    36  	repoLocator api.RepositoryLocator
    37  }
    38  
    39  func NewFactory(config coreconfig.ReadWriter, repoLocator api.RepositoryLocator) (factory apiRequirementFactory) {
    40  	return apiRequirementFactory{config, repoLocator}
    41  }
    42  
    43  func (f apiRequirementFactory) NewApplicationRequirement(name string) ApplicationRequirement {
    44  	return NewApplicationRequirement(
    45  		name,
    46  		f.repoLocator.GetApplicationRepository(),
    47  	)
    48  }
    49  
    50  func (f apiRequirementFactory) NewDEAApplicationRequirement(name string) DEAApplicationRequirement {
    51  	return NewDEAApplicationRequirement(
    52  		name,
    53  		f.repoLocator.GetApplicationRepository(),
    54  	)
    55  }
    56  
    57  func (f apiRequirementFactory) NewDiegoApplicationRequirement(name string) DiegoApplicationRequirement {
    58  	return NewDiegoApplicationRequirement(
    59  		name,
    60  		f.repoLocator.GetApplicationRepository(),
    61  	)
    62  }
    63  
    64  func (f apiRequirementFactory) NewServiceInstanceRequirement(name string) ServiceInstanceRequirement {
    65  	return NewServiceInstanceRequirement(
    66  		name,
    67  		f.repoLocator.GetServiceRepository(),
    68  	)
    69  }
    70  
    71  func (f apiRequirementFactory) NewLoginRequirement() Requirement {
    72  	return NewLoginRequirement(
    73  		f.config,
    74  	)
    75  }
    76  
    77  func (f apiRequirementFactory) NewRoutingAPIRequirement() Requirement {
    78  	req := Requirements{
    79  		f.NewMinAPIVersionRequirement(T("This command"), cf.TCPRoutingMinimumAPIVersion),
    80  		NewRoutingAPIRequirement(
    81  			f.config,
    82  		),
    83  	}
    84  
    85  	return req
    86  }
    87  
    88  func (f apiRequirementFactory) NewSpaceRequirement(name string) SpaceRequirement {
    89  	return NewSpaceRequirement(
    90  		name,
    91  		f.repoLocator.GetSpaceRepository(),
    92  	)
    93  }
    94  
    95  func (f apiRequirementFactory) NewTargetedSpaceRequirement() Requirement {
    96  	return NewTargetedSpaceRequirement(
    97  		f.config,
    98  	)
    99  }
   100  
   101  func (f apiRequirementFactory) NewTargetedOrgRequirement() TargetedOrgRequirement {
   102  	return NewTargetedOrgRequirement(
   103  		f.config,
   104  	)
   105  }
   106  
   107  func (f apiRequirementFactory) NewOrganizationRequirement(name string) OrganizationRequirement {
   108  	return NewOrganizationRequirement(
   109  		name,
   110  		f.repoLocator.GetOrganizationRepository(),
   111  	)
   112  }
   113  
   114  func (f apiRequirementFactory) NewDomainRequirement(name string) DomainRequirement {
   115  	return NewDomainRequirement(
   116  		name,
   117  		f.config,
   118  		f.repoLocator.GetDomainRepository(),
   119  	)
   120  }
   121  
   122  func (f apiRequirementFactory) NewUserRequirement(username string, wantGUID bool) UserRequirement {
   123  	return NewUserRequirement(
   124  		username,
   125  		f.repoLocator.GetUserRepository(),
   126  		wantGUID,
   127  	)
   128  }
   129  
   130  func (f apiRequirementFactory) NewBuildpackRequirement(buildpack string) BuildpackRequirement {
   131  	return NewBuildpackRequirement(
   132  		buildpack,
   133  		f.repoLocator.GetBuildpackRepository(),
   134  	)
   135  }
   136  
   137  func (f apiRequirementFactory) NewAPIEndpointRequirement() Requirement {
   138  	return NewAPIEndpointRequirement(
   139  		f.config,
   140  	)
   141  }
   142  
   143  func (f apiRequirementFactory) NewMinAPIVersionRequirement(commandName string, requiredVersion semver.Version) Requirement {
   144  	r := NewMinAPIVersionRequirement(
   145  		f.config,
   146  		commandName,
   147  		requiredVersion,
   148  	)
   149  
   150  	refresher := coreconfig.APIConfigRefresher{
   151  		Endpoint:     f.config.APIEndpoint(),
   152  		EndpointRepo: f.repoLocator.GetEndpointRepository(),
   153  		Config:       f.config,
   154  	}
   155  
   156  	return NewConfigRefreshingRequirement(r, refresher)
   157  }
   158  
   159  func (f apiRequirementFactory) NewMaxAPIVersionRequirement(commandName string, maximumVersion semver.Version) Requirement {
   160  	return NewMaxAPIVersionRequirement(
   161  		f.config,
   162  		commandName,
   163  		maximumVersion,
   164  	)
   165  }
   166  
   167  func (f apiRequirementFactory) NewUsageRequirement(cmd Usable, errorMessage string, pred func() bool) Requirement {
   168  	return NewUsageRequirement(cmd, errorMessage, pred)
   169  }
   170  
   171  func (f apiRequirementFactory) NewNumberArguments(passedArgs []string, expectedArgs ...string) Requirement {
   172  	return NewNumberArguments(passedArgs, expectedArgs)
   173  }