Skip to content

Commit

Permalink
fix: make deleting unmatched images optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nhoss2 committed Jul 4, 2024
1 parent 0b6060a commit 24d3d3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logger } from "./logger";
import { getClient, deleteFilesBulk } from "./s3";
import { buildState } from "./state";

export const run = async (): Promise<void> => {
export const run = async (deleteUnmatched?: boolean): Promise<void> => {
try {
const config = getConfig();
const { bucketName, inputConfig } = config;
Expand All @@ -17,7 +17,7 @@ export const run = async (): Promise<void> => {

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);
}
Expand Down

0 comments on commit 24d3d3b

Please sign in to comment.