Skip to content

Commit abaa6f8

Browse files
CopilotRetricSu
andauthored
Add -d, --data flag to offckb clean for selective data removal (#330)
* Initial plan * Add -d, --data option to clean command for data-only cleanup Co-authored-by: RetricSu <23436060+RetricSu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RetricSu <23436060+RetricSu@users.noreply.github.com>
1 parent ed91c20 commit abaa6f8

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

src/cli.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ program
105105
return printSystemScripts({ style: exportStyle, network });
106106
});
107107

108-
program.command('clean').description('Clean the devnet data, need to stop running the chain first').action(clean);
108+
program
109+
.command('clean')
110+
.description('Clean the devnet data, need to stop running the chain first')
111+
.option('-d, --data', 'Only remove chain data, keep devnet config files')
112+
.action((options: { data?: boolean }) => clean(options));
109113
program.command('accounts').description('Print account list info').action(accounts);
110114

111115
program

src/cmd/clean.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,42 @@ import { isFolderExists } from '../util/fs';
33
import { readSettings } from '../cfg/setting';
44
import { logger } from '../util/logger';
55

6-
export function clean() {
6+
export interface CleanOptions {
7+
data?: boolean;
8+
}
9+
10+
export function clean(options?: CleanOptions) {
711
const settings = readSettings();
812
const allDevnetDataPath = settings.devnet.configPath;
9-
// this is the root folder of devnet, it contains config, data, debugFullTransactions, transactions, failed-transactions, contracts
10-
if (isFolderExists(allDevnetDataPath)) {
11-
try {
12-
fs.rmSync(allDevnetDataPath, { recursive: true });
13-
logger.info(`Chain data cleaned.`);
14-
} catch (error: unknown) {
15-
logger.info(`Did you stop running the chain first?`);
16-
logger.error((error as Error).message);
13+
const dataOnly = options?.data || false;
14+
15+
if (dataOnly) {
16+
// Only clean the chain data subdirectory
17+
const chainDataPath = settings.devnet.dataPath;
18+
if (isFolderExists(chainDataPath)) {
19+
try {
20+
fs.rmSync(chainDataPath, { recursive: true });
21+
logger.info(`Chain data cleaned. Devnet config files preserved.`);
22+
} catch (error: unknown) {
23+
logger.info(`Did you stop running the chain first?`);
24+
logger.error((error as Error).message);
25+
}
26+
} else {
27+
logger.info(`Nothing to clean. Chain data directory ${chainDataPath} not found.`);
1728
}
1829
} else {
19-
logger.info(`Nothing to clean. Devnet data directory ${allDevnetDataPath} not found.`);
30+
// Clean everything - the original behavior
31+
// this is the root folder of devnet, it contains config, data, debugFullTransactions, transactions, failed-transactions, contracts
32+
if (isFolderExists(allDevnetDataPath)) {
33+
try {
34+
fs.rmSync(allDevnetDataPath, { recursive: true });
35+
logger.info(`Chain data cleaned.`);
36+
} catch (error: unknown) {
37+
logger.info(`Did you stop running the chain first?`);
38+
logger.error((error as Error).message);
39+
}
40+
} else {
41+
logger.info(`Nothing to clean. Devnet data directory ${allDevnetDataPath} not found.`);
42+
}
2043
}
2144
}

0 commit comments

Comments
 (0)