Skip to content

Commit

Permalink
feat(cli): disable progress bar on --no-progress or --watch
Browse files Browse the repository at this point in the history
  • Loading branch information
eligao committed Dec 26, 2024
1 parent a8c20f6 commit 32ba427
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 10 additions & 5 deletions cli/src/commands/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface UploadOptionsDto {
albumName?: string;
includeHidden?: boolean;
concurrency: number;
progress?: boolean;
watch?: boolean;
}

Expand Down Expand Up @@ -162,7 +163,7 @@ const scan = async (pathsToCrawl: string[], options: UploadOptionsDto) => {
return files;
};

export const checkForDuplicates = async (files: string[], { concurrency, skipHash }: UploadOptionsDto) => {
export const checkForDuplicates = async (files: string[], { concurrency, skipHash, progress }: UploadOptionsDto) => {
if (skipHash) {
console.log('Skipping hash check, assuming all files are new');
return { newFiles: files, duplicates: [] };
Expand All @@ -173,8 +174,12 @@ export const checkForDuplicates = async (files: string[], { concurrency, skipHas
Presets.shades_classic,
);

const hashProgressBar = multiBar.create(files.length, 0, { message: 'Hashing files ' });
const checkProgressBar = multiBar.create(files.length, 0, { message: 'Checking for duplicates' });
const hashProgressBar = progress
? multiBar.create(files.length, 0, { message: 'Hashing files ' })
: undefined;
const checkProgressBar = progress
? multiBar.create(files.length, 0, { message: 'Checking for duplicates' })
: undefined;

const newFiles: string[] = [];
const duplicates: Asset[] = [];
Expand All @@ -194,7 +199,7 @@ export const checkForDuplicates = async (files: string[], { concurrency, skipHas
}
}

checkProgressBar.increment(assets.length);
checkProgressBar?.increment(assets.length);
},
{ concurrency, retry: 3 },
);
Expand All @@ -214,7 +219,7 @@ export const checkForDuplicates = async (files: string[], { concurrency, skipHas
void checkBulkUploadQueue.push(batch);
}

hashProgressBar.increment();
hashProgressBar?.increment();
return results;
},
{ concurrency, retry: 3 },
Expand Down
6 changes: 5 additions & 1 deletion cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ program
.default(4),
)
.addOption(new Option('--delete', 'Delete local assets after upload').env('IMMICH_DELETE_ASSETS'))
.addOption(new Option('--no-progress', 'Hide progress bars').env('IMMICH_PROGRESS_BAR').default(true))
.addOption(
new Option('--watch', 'Watch for changes and upload automatically').env('IMMICH_WATCH_CHANGES').default(false),
new Option('--watch', 'Watch for changes and upload automatically')
.env('IMMICH_WATCH_CHANGES')
.default(false)
.implies({ progress: false }),
)
.argument('[paths...]', 'One or more paths to assets to be uploaded')
.action((paths, options) => upload(paths, program.opts(), options));
Expand Down

0 comments on commit 32ba427

Please sign in to comment.