Skip to content

Commit 4dd491b

Browse files
committed
feat(command): add reset command
Used to reset the CLI to the state it was first installed in
1 parent 5cfd391 commit 4dd491b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/command/reset.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { getConfirm } from '@/qa';
2+
import { useEnvVar } from '@/utils';
3+
import ora from 'ora';
4+
import VError from 'verror';
5+
6+
const reset = async () => {
7+
const confirm = await getConfirm(
8+
'All configuration files and cache will be deleted',
9+
);
10+
const sp = ora();
11+
12+
if (!confirm) {
13+
sp.fail('Cancel');
14+
return;
15+
}
16+
17+
sp.start('Reset');
18+
try {
19+
await fs.rm(useEnvVar().__dir_cache, { recursive: true });
20+
} catch (e) {
21+
sp.fail(`Reset fail because: ${(e as Error).message}`);
22+
throw new VError(e);
23+
}
24+
sp.succeed('Done');
25+
};
26+
27+
export default reset;

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import VError from 'verror';
66

77
const errHandle = (err: Error | VError) => {
88
if (err instanceof VError) {
9-
console.error(chalk.black.bgRed(' ERROR ') ,chalk.red(err.message));
9+
console.error(chalk.black.bgRed(' ERROR '), chalk.red(err.message));
1010
process.exit(0);
1111
} else {
1212
console.error(chalk.black.bgRed(' UNCATCH ERROR '), chalk.red(err.stack));
@@ -34,8 +34,11 @@ program
3434
.description('Manage repository')
3535
.action((opt) => cmdRepo({ opt }));
3636

37+
program.command('reset').action(() => reset());
38+
3739
program.parse();
3840

3941
import type { Hooks as _Hooks } from './Hook';
42+
import reset from './command/reset';
4043
export type { InjectHook, BaseHook } from './Hook';
4144
export type Hooks = Partial<_Hooks>;

0 commit comments

Comments
 (0)