diff --git a/src/cli.ts b/src/cli.ts index 2acb8e3..3d96b70 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -9,8 +9,13 @@ const program = new Command(); program .command("run") .description("process all images") - .action(async () => { - await run(); + .option( + "--delete", + "Delete output images that dont have a matching input image" + ) + .action(async (options: { delete?: boolean }) => { + const { delete: deleteUnmatched } = options; + await run(deleteUnmatched); }); program diff --git a/src/run.ts b/src/run.ts index 492fd02..b937a3e 100644 --- a/src/run.ts +++ b/src/run.ts @@ -4,7 +4,7 @@ import { logger } from "./logger"; import { getClient, deleteFilesBulk } from "./s3"; import { buildState } from "./state"; -export const run = async (): Promise => { +export const run = async (deleteUnmatched?: boolean): Promise => { try { const config = getConfig(); const { bucketName, inputConfig } = config; @@ -17,7 +17,7 @@ export const run = async (): Promise => { await processImages(state, inputConfig, bucketName); - if (state.unmatchedOutputImages.length > 0) { + if (state.unmatchedOutputImages.length > 0 && deleteUnmatched) { logger.info("deleting unmatched output images"); await deleteFilesBulk(bucketName, state.unmatchedOutputImages); }