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

Fix invalid usage of create-space #287

Merged
merged 2 commits into from
Nov 24, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cf/commands/application/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (cmd *ShowApp) Metadata() command_metadata.CommandMetadata {
}

func (cmd *ShowApp) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) < 1 {
if len(c.Args()) != 1 {
cmd.ui.FailWithUsage(c)
}

Expand Down
2 changes: 1 addition & 1 deletion cf/commands/application/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ = Describe("app Command", func() {
Expect(runCommand("cf-plays-dwarf-fortress")).To(BeFalse())
})

It("fails with usage when no arguments are given", func() {
It("fails with usage when not provided exactly one arg", func() {
passed := runCommand()
Expect(ui.FailedWithUsage).To(BeTrue())
Expect(passed).To(BeFalse())
Expand Down
3 changes: 3 additions & 0 deletions cf/commands/application/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func (cmd ListApps) Metadata() command_metadata.CommandMetadata {
}

func (cmd ListApps) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
reqs = []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedSpaceRequirement(),
Expand Down
10 changes: 8 additions & 2 deletions cf/commands/application/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ var _ = Describe("list-apps command", func() {
}
})

runCommand := func() bool {
runCommand := func(args ...string) bool {
cmd := NewListApps(ui, configRepo, appSummaryRepo)
return testcmd.RunCommand(cmd, []string{}, requirementsFactory)
return testcmd.RunCommand(cmd, args, requirementsFactory)
}

Describe("requirements", func() {
Expand All @@ -50,6 +50,12 @@ var _ = Describe("list-apps command", func() {

Expect(runCommand()).To(BeFalse())
})
It("should fail with usage when provided any arguments", func() {
requirementsFactory.LoginSuccess = true
requirementsFactory.TargetedSpaceSuccess = true
Expect(runCommand("blahblah")).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})
})

Context("when the user is logged in and a space is targeted", func() {
Expand Down
2 changes: 1 addition & 1 deletion cf/commands/application/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (cmd *DeleteApp) Metadata() command_metadata.CommandMetadata {
}

func (cmd *DeleteApp) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) == 0 {
if len(c.Args()) != 1 {
cmd.ui.FailWithUsage(c)
}

Expand Down
2 changes: 1 addition & 1 deletion cf/commands/application/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var _ = Describe("delete app command", func() {
requirementsFactory.LoginSuccess = true
})

It("provides the user usage text when no app name is given", func() {
It("fails with usage when not provided exactly one arg", func() {
runCommand()
Expect(ui.FailedWithUsage).To(BeTrue())
})
Expand Down
2 changes: 1 addition & 1 deletion cf/commands/application/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (cmd *Restart) Metadata() command_metadata.CommandMetadata {
}

func (cmd *Restart) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) == 0 {
if len(c.Args()) != 1 {
cmd.ui.FailWithUsage(c)
}

Expand Down
2 changes: 1 addition & 1 deletion cf/commands/application/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var _ = Describe("restart command", func() {
}

Describe("requirements", func() {
It("fails with usage when an app name is not given", func() {
It("fails with usage when not provided exactly one arg", func() {
requirementsFactory.LoginSuccess = true
runCommand()
Expect(ui.FailedWithUsage).To(BeTrue())
Expand Down
2 changes: 1 addition & 1 deletion cf/commands/application/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (cmd *Start) Metadata() command_metadata.CommandMetadata {
}

func (cmd *Start) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) == 0 {
if len(c.Args()) != 1 {
cmd.ui.FailWithUsage(c)
}

Expand Down
2 changes: 1 addition & 1 deletion cf/commands/application/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ var _ = Describe("start command", func() {
requirementsFactory.LoginSuccess = true
})

It("fails with usage when provided with no args", func() {
It("fails with usage when not provided exactly one arg", func() {
config := testconfig.NewRepository()
displayApp := &testcmd.FakeAppDisplayer{}
appRepo := &testApplication.FakeApplicationRepository{}
Expand Down
3 changes: 3 additions & 0 deletions cf/commands/buildpack/buildpacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func (cmd ListBuildpacks) Metadata() command_metadata.CommandMetadata {
}

func (cmd ListBuildpacks) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
reqs = []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
Expand Down
6 changes: 6 additions & 0 deletions cf/commands/buildpack/buildpacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ var _ = Describe("ListBuildpacks", func() {
return testcmd.RunCommand(cmd, args, requirementsFactory)
}

It("should fail with usage when provided any arguments", func() {
requirementsFactory.LoginSuccess = true
Expect(runCommand("blahblah")).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})

It("fails requirements when login fails", func() {
Expect(runCommand()).To(BeFalse())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func (cmd RunningEnvironmentVariableGroup) Metadata() command_metadata.CommandMe
}

func (cmd RunningEnvironmentVariableGroup) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) ([]requirements.Requirement, error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ var _ = Describe("running-environment-variable-group command", func() {
requirementsFactory.LoginSuccess = false
Expect(runCommand()).ToNot(HavePassedRequirements())
})
It("should fail with usage when provided any arguments", func() {
requirementsFactory.LoginSuccess = true
Expect(runCommand("blahblah")).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})
})

Describe("when logged in", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func (cmd StagingEnvironmentVariableGroup) Metadata() command_metadata.CommandMe
}

func (cmd StagingEnvironmentVariableGroup) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) ([]requirements.Requirement, error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ var _ = Describe("staging-environment-variable-group command", func() {
requirementsFactory.LoginSuccess = false
Expect(runCommand()).ToNot(HavePassedRequirements())
})
It("should fail with usage when provided any arguments", func() {
requirementsFactory.LoginSuccess = true
Expect(runCommand("blahblah")).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})
})

Describe("when logged in", func() {
Expand Down
5 changes: 4 additions & 1 deletion cf/commands/featureflag/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func (cmd ListFeatureFlags) Metadata() command_metadata.CommandMetadata {
}
}

func (cmd ListFeatureFlags) GetRequirements(requirementsFactory requirements.Factory, _ *cli.Context) ([]requirements.Requirement, error) {
func (cmd ListFeatureFlags) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) ([]requirements.Requirement, error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
Expand Down
5 changes: 5 additions & 0 deletions cf/commands/featureflag/feature_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ var _ = Describe("feature-flags command", func() {
requirementsFactory.LoginSuccess = false
Expect(runCommand()).ToNot(HavePassedRequirements())
})
It("should fail with usage when provided any arguments", func() {
requirementsFactory.LoginSuccess = true
Expect(runCommand("blahblah")).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})
})

Describe("when logged in", func() {
Expand Down
4 changes: 4 additions & 0 deletions cf/commands/organization/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (cmd ListOrgs) Metadata() command_metadata.CommandMetadata {
}

func (cmd ListOrgs) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}

reqs = []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
Expand Down
10 changes: 8 additions & 2 deletions cf/commands/organization/orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ var _ = Describe("org command", func() {
requirementsFactory *testreq.FakeReqFactory
)

runCommand := func() bool {
runCommand := func(args ...string) bool {
cmd := organization.NewListOrgs(ui, configRepo, orgRepo)
return testcmd.RunCommand(cmd, []string{}, requirementsFactory)
return testcmd.RunCommand(cmd, args, requirementsFactory)
}

BeforeEach(func() {
Expand All @@ -41,6 +41,12 @@ var _ = Describe("org command", func() {

Expect(runCommand()).To(BeFalse())
})
It("should fail with usage when provided any arguments", func() {
requirementsFactory.LoginSuccess = true
Expect(runCommand("blahblah")).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})

})

Context("when there are orgs to be listed", func() {
Expand Down
5 changes: 4 additions & 1 deletion cf/commands/plugin/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ func (cmd *Plugins) Metadata() command_metadata.CommandMetadata {
}
}

func (cmd *Plugins) GetRequirements(_ requirements.Factory, _ *cli.Context) (req []requirements.Requirement, err error) {
func (cmd *Plugins) GetRequirements(_ requirements.Factory, c *cli.Context) (req []requirements.Requirement, err error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
return
}

Expand Down
5 changes: 5 additions & 0 deletions cf/commands/plugin/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ var _ = Describe("Plugins", func() {
cmd := NewPlugins(ui, config)
return testcmd.RunCommand(cmd, args, requirementsFactory)
}
It("should fail with usage when provided any arguments", func() {
requirementsFactory.LoginSuccess = true
Expect(runCommand("blahblah")).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})

It("returns a list of available methods of a plugin", func() {
config.PluginsReturns(map[string]plugin_config.PluginMetadata{
Expand Down
3 changes: 3 additions & 0 deletions cf/commands/quota/quotas.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func (cmd *ListQuotas) Metadata() command_metadata.CommandMetadata {
}

func (cmd *ListQuotas) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
reqs = []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
Expand Down
9 changes: 7 additions & 2 deletions cf/commands/quota/quotas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ var _ = Describe("quotas command", func() {
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
})

runCommand := func() bool {
runCommand := func(args ...string) bool {
cmd := NewListQuotas(ui, testconfig.NewRepositoryWithDefaults(), quotaRepo)
return testcmd.RunCommand(cmd, []string{}, requirementsFactory)
return testcmd.RunCommand(cmd, args, requirementsFactory)
}

Describe("requirements", func() {
It("requires the user to be logged in", func() {
requirementsFactory.LoginSuccess = false
Expect(runCommand()).ToNot(HavePassedRequirements())
})
It("should fail with usage when provided any arguments", func() {
requirementsFactory.LoginSuccess = true
Expect(runCommand("blahblah")).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})
})

Context("when quotas exist", func() {
Expand Down
3 changes: 3 additions & 0 deletions cf/commands/route/delete_orphaned_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func (cmd DeleteOrphanedRoutes) Metadata() command_metadata.CommandMetadata {
}

func (cmd DeleteOrphanedRoutes) GetRequirements(reqFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
reqs = append(reqs, reqFactory.NewLoginRequirement())
return
}
Expand Down
6 changes: 6 additions & 0 deletions cf/commands/route/delete_orphaned_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ var _ = Describe("delete-orphaned-routes command", func() {
_, passed := callDeleteOrphanedRoutes("y", []string{}, reqFactory, routeRepo)
Expect(passed).To(BeFalse())
})
It("should fail with usage when provided any arguments", func() {
reqFactory.LoginSuccess = true
ui, passed := callDeleteOrphanedRoutes("y", []string{"blahblah"}, reqFactory, routeRepo)
Expect(passed).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})

Context("when logged in successfully", func() {

Expand Down
3 changes: 3 additions & 0 deletions cf/commands/route/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func (cmd ListRoutes) Metadata() command_metadata.CommandMetadata {
}

func (cmd ListRoutes) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) ([]requirements.Requirement, error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
return []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedSpaceRequirement(),
Expand Down
6 changes: 6 additions & 0 deletions cf/commands/route/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ var _ = Describe("routes command", func() {

Expect(runCommand()).To(BeFalse())
})
It("should fail with usage when provided any arguments", func() {
requirementsFactory.LoginSuccess = true
requirementsFactory.TargetedSpaceSuccess = true
Expect(runCommand("blahblah")).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})
})

Context("when there are routes", func() {
Expand Down
9 changes: 1 addition & 8 deletions cf/commands/service/delete_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,9 @@ func (cmd *DeleteService) Metadata() command_metadata.CommandMetadata {
}

func (cmd *DeleteService) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
var serviceName string

if len(c.Args()) == 1 {
serviceName = c.Args()[0]
}

if serviceName == "" {
if len(c.Args()) != 1 {
cmd.ui.FailWithUsage(c)
}

reqs = []requirements.Requirement{requirementsFactory.NewLoginRequirement()}
return
}
Expand Down
2 changes: 1 addition & 1 deletion cf/commands/service/delete_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var _ = Describe("delete-service command", func() {
requirementsFactory.LoginSuccess = true
})

It("fails with usage when no service name is given", func() {
It("fails with usage when not provided exactly one arg", func() {
runCommand()
Expect(ui.FailedWithUsage).To(BeTrue())
})
Expand Down
3 changes: 3 additions & 0 deletions cf/commands/service/marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func (cmd MarketplaceServices) Metadata() command_metadata.CommandMetadata {
}

func (cmd MarketplaceServices) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
reqs = append(reqs, requirementsFactory.NewApiEndpointRequirement())
return
}
Expand Down
7 changes: 7 additions & 0 deletions cf/commands/service/marketplace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ var _ = Describe("marketplace command", func() {

Expect(testcmd.RunCommand(cmd, []string{}, requirementsFactory)).To(BeFalse())
})
It("should fail with usage when provided any arguments", func() {
config := testconfig.NewRepository()
cmd := NewMarketplaceServices(ui, config, serviceBuilder)
requirementsFactory.ApiEndpointSuccess = true
Expect(testcmd.RunCommand(cmd, []string{"blahblah"}, requirementsFactory)).To(BeFalse())
Expect(ui.FailedWithUsage).To(BeTrue())
})
})
})

Expand Down
3 changes: 3 additions & 0 deletions cf/commands/service/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func (cmd ListServices) Metadata() command_metadata.CommandMetadata {
}

func (cmd ListServices) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
reqs = append(reqs,
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedSpaceRequirement(),
Expand Down