Skip to content

Commit

Permalink
improvement(cli): allow garden delete services with no arguments
Browse files Browse the repository at this point in the history
Basically this makes it easy to delete all services in a namespace.
Sort of a silly omission to begin with.
  • Loading branch information
edvald authored and thsig committed Mar 18, 2021
1 parent 8e0ac89 commit 6a728e5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
8 changes: 4 additions & 4 deletions core/src/commands/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export class DeleteEnvironmentCommand extends Command {
export const deleteServiceArgs = {
services: new StringsParameter({
help: "The name(s) of the service(s) to delete. Use comma as a separator to specify multiple services.",
required: true,
}),
}
type DeleteServiceArgs = typeof deleteServiceArgs
Expand All @@ -142,13 +141,14 @@ export class DeleteServiceCommand extends Command {
streamEvents = true

description = dedent`
Deletes (i.e. un-deploys) the specified services. Note that this command does not take into account any
services depending on the deleted service, and might therefore leave the project in an unstable state.
Running \`garden deploy\` will re-deploy any missing services.
Deletes (i.e. un-deploys) the specified services. Deletes all services in the project if no arguments are provided.
Note that this command does not take into account any services depending on the deleted service/services, and might
therefore leave the project in an unstable state. Running \`garden deploy\` will re-deploy any missing services.
Examples:
garden delete service my-service # deletes my-service
garden delete service # deletes all deployed services in the project
`

outputsSchema = () =>
Expand Down
4 changes: 2 additions & 2 deletions core/test/unit/src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ describe("processCliArgs", () => {
// })

it("throws an error when a required positional argument is missing", () => {
const cmd = new DeleteServiceCommand()
const cmd = new RunTaskCommand()
expectError(
() => parseAndProcess([], cmd),
(err) => expect(stripAnsi(err.message)).to.equal("Missing required argument services")
(err) => expect(stripAnsi(err.message)).to.equal("Missing required argument task")
)
})

Expand Down
30 changes: 30 additions & 0 deletions core/test/unit/src/commands/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ describe("DeleteServiceCommand", () => {
ingresses: [],
detail: {},
},
"service-c": {
state: "unknown",
ingresses: [],
detail: {},
},
"service-d": {
state: "unknown",
ingresses: [],
detail: {},
},
}

const testProvider = createGardenPlugin({
Expand Down Expand Up @@ -225,6 +235,26 @@ describe("DeleteServiceCommand", () => {
})
})

it("should delete all services if none are specified", async () => {
const garden = await TestGarden.factory(projectRootB, { plugins })
const log = garden.log

const { result } = await command.action({
garden,
log,
headerLog: log,
footerLog: log,
args: { services: undefined },
opts: withDefaultGlobalOpts({}),
})
expect(result).to.eql({
"service-a": { forwardablePorts: [], state: "unknown", ingresses: [], detail: {}, outputs: {} },
"service-b": { forwardablePorts: [], state: "unknown", ingresses: [], detail: {}, outputs: {} },
"service-c": { forwardablePorts: [], state: "unknown", ingresses: [], detail: {}, outputs: {} },
"service-d": { forwardablePorts: [], state: "unknown", ingresses: [], detail: {}, outputs: {} },
})
})

it("should be protected", async () => {
expect(command.protected).to.be.true
})
Expand Down
11 changes: 6 additions & 5 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,27 +503,28 @@ serviceStatuses:

**Deletes running services.**

Deletes (i.e. un-deploys) the specified services. Note that this command does not take into account any
services depending on the deleted service, and might therefore leave the project in an unstable state.
Running `garden deploy` will re-deploy any missing services.
Deletes (i.e. un-deploys) the specified services. Deletes all services in the project if no arguments are provided.
Note that this command does not take into account any services depending on the deleted service/services, and might
therefore leave the project in an unstable state. Running `garden deploy` will re-deploy any missing services.

Examples:

garden delete service my-service # deletes my-service
garden delete service # deletes all deployed services in the project

| Supported in workflows | |
| ---------------------- |---|
| Yes | |

#### Usage

garden delete service <services>
garden delete service [services]

#### Arguments

| Argument | Required | Description |
| -------- | -------- | ----------- |
| `services` | Yes | The name(s) of the service(s) to delete. Use comma as a separator to specify multiple services.
| `services` | No | The name(s) of the service(s) to delete. Use comma as a separator to specify multiple services.


#### Outputs
Expand Down

0 comments on commit 6a728e5

Please sign in to comment.