11import fs from 'fs-extra' ;
22import { Command } from 'commander' ;
33import { getTmpPath , getDefaultTmpRoot } from '../core/tmp.js' ;
4+ import { createLogger } from '../core/logger.js' ;
45
56export function registerCacheCommand ( program : Command ) : void {
67 const cache = program . command ( 'cache' ) . description ( 'Manage the CLI cache' ) ;
@@ -11,35 +12,39 @@ export function registerCacheCommand(program: Command): void {
1112 . option ( '--packages' , 'Clear only package cache' )
1213 . option ( '--builds' , 'Clear only build cache' )
1314 . option ( '--tmp-dir <dir>' , 'Custom temp directory' )
15+ . option ( '--silent' , 'Suppress output' )
1416 . action ( async ( options ) => {
17+ const logger = createLogger ( { silent : options . silent } ) ;
1518 const tmpDir = options . tmpDir ;
1619 if ( options . packages ) {
1720 await fs . remove ( getTmpPath ( tmpDir , 'cache' , 'packages' ) ) ;
18- console . log ( 'Package cache cleared' ) ;
21+ logger . log ( 'Package cache cleared' ) ;
1922 } else if ( options . builds ) {
2023 await fs . remove ( getTmpPath ( tmpDir , 'cache' , 'builds' ) ) ;
21- console . log ( 'Build cache cleared' ) ;
24+ logger . log ( 'Build cache cleared' ) ;
2225 } else {
2326 await fs . remove ( getTmpPath ( tmpDir , 'cache' ) ) ;
24- console . log ( 'All caches cleared' ) ;
27+ logger . log ( 'All caches cleared' ) ;
2528 }
2629 } ) ;
2730
2831 cache
2932 . command ( 'info' )
3033 . description ( 'Show cache statistics' )
3134 . option ( '--tmp-dir <dir>' , 'Custom temp directory' )
35+ . option ( '--silent' , 'Suppress output' )
3236 . action ( async ( options ) => {
37+ const logger = createLogger ( { silent : options . silent } ) ;
3338 const tmpDir = options . tmpDir ;
3439 const packagesDir = getTmpPath ( tmpDir , 'cache' , 'packages' ) ;
3540 const buildsDir = getTmpPath ( tmpDir , 'cache' , 'builds' ) ;
3641
3742 const packageCount = await countEntries ( packagesDir ) ;
3843 const buildCount = await countEntries ( buildsDir ) ;
3944
40- console . log ( `Cache directory: ${ getTmpPath ( tmpDir , 'cache' ) } ` ) ;
41- console . log ( `Cached packages: ${ packageCount } ` ) ;
42- console . log ( `Cached builds: ${ buildCount } ` ) ;
45+ logger . log ( `Cache directory: ${ getTmpPath ( tmpDir , 'cache' ) } ` ) ;
46+ logger . log ( `Cached packages: ${ packageCount } ` ) ;
47+ logger . log ( `Cached builds: ${ buildCount } ` ) ;
4348 } ) ;
4449}
4550
@@ -51,10 +56,12 @@ export function registerCleanCommand(program: Command): void {
5156 . command ( 'clean' )
5257 . description ( 'Clear the entire temp directory (.tmp/)' )
5358 . option ( '--tmp-dir <dir>' , 'Custom temp directory' )
59+ . option ( '--silent' , 'Suppress output' )
5460 . action ( async ( options ) => {
61+ const logger = createLogger ( { silent : options . silent } ) ;
5562 const tmpDir = options . tmpDir || getDefaultTmpRoot ( ) ;
5663 await fs . remove ( tmpDir ) ;
57- console . log ( `Temp directory cleared: ${ tmpDir } ` ) ;
64+ logger . log ( `Temp directory cleared: ${ tmpDir } ` ) ;
5865 } ) ;
5966}
6067
0 commit comments