Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/cleanup-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,35 @@ const commandName = `cleanup`;

const region = process.env[`AWS_REGION`] || process.env[`AWS_DEFAULT_REGION`];

export const cleanupCommand: CommandModule<{}, { readonly yes: boolean }> = {
export const cleanupCommand: CommandModule<
{},
{ readonly yes: boolean; readonly hostedZoneName?: string }
> = {
command: `${commandName} [options]`,
describe: `Deletes unused resources created by aws-simple for same region using new default region tag.
If resource does not contain this tag, it will be deleted even if other regions are using it.`,

builder: (argv) =>
argv
.options(`hosted-zone-name`, {
describe: `An optional hosted zone name to filter stacks`,
string: true,
})
.options(`yes`, {
describe: `Confirm the deletion of unused resources for region: ${region}`,
boolean: true,
default: false,
})
.example([[`npx $0 ${commandName}`], [`npx $0 ${commandName} --yes`]]),
.example([
[`npx $0 ${commandName}`],
[`npx $0 ${commandName} --hosted-zone-name example.com`],
[`npx $0 ${commandName} --yes`],
]),

handler: async (args): Promise<void> => {
print.info(`Searching unused resources for region ${region}...`);

const stacks = await findStacks();
const stacks = await findStacks(args.hostedZoneName);
const allResourceIds = new Set<string>();

for (const stack of stacks) {
Expand Down