11import chalk from 'chalk' ;
2+ import { createInterface } from 'readline/promises' ;
23import { Logger } from 'mycoder-agent' ;
34
45import { SharedOptions } from '../options.js' ;
56import {
67 getConfig ,
78 getDefaultConfig ,
89 updateConfig ,
10+ clearAllConfig ,
911} from '../settings/config.js' ;
1012import { nameToLogIndex } from '../utils/nameToLogIndex.js' ;
1113
14+ /**
15+ * Prompts the user for confirmation with a yes/no question
16+ * @param question The question to ask the user
17+ * @returns True if the user confirmed, false otherwise
18+ */
19+ async function confirm ( question : string ) : Promise < boolean > {
20+ const rl = createInterface ( {
21+ input : process . stdin ,
22+ output : process . stdout ,
23+ } ) ;
24+
25+ try {
26+ const answer = await rl . question ( `${ question } (y/N): ` ) ;
27+ return answer . toLowerCase ( ) === 'y' || answer . toLowerCase ( ) === 'yes' ;
28+ } finally {
29+ rl . close ( ) ;
30+ }
31+ }
32+
1233import type { CommandModule , ArgumentsCamelCase } from 'yargs' ;
1334
1435export interface ConfigOptions extends SharedOptions {
1536 command : 'get' | 'set' | 'list' | 'clear' ;
1637 key ?: string ;
1738 value ?: string ;
39+ all ?: boolean ;
1840}
1941
2042export const command : CommandModule < SharedOptions , ConfigOptions > = {
@@ -36,6 +58,11 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
3658 describe : 'Configuration value (for set command)' ,
3759 type : 'string' ,
3860 } )
61+ . option ( 'all' , {
62+ describe : 'Clear all configuration settings (for clear command)' ,
63+ type : 'boolean' ,
64+ default : false ,
65+ } )
3966 . example ( '$0 config list' , 'List all configuration values' )
4067 . example (
4168 '$0 config get githubMode' ,
@@ -45,6 +72,10 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
4572 . example (
4673 '$0 config clear customPrompt' ,
4774 'Reset customPrompt to default value' ,
75+ )
76+ . example (
77+ '$0 config clear --all' ,
78+ 'Clear all configuration settings' ,
4879 ) as any ; // eslint-disable-line @typescript-eslint/no-explicit-any
4980 } ,
5081 handler : async ( argv : ArgumentsCamelCase < ConfigOptions > ) => {
@@ -153,8 +184,26 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
153184
154185 // Handle 'clear' command
155186 if ( argv . command === 'clear' ) {
187+ // Check if --all flag is provided
188+ if ( argv . all ) {
189+ // Confirm with the user before clearing all settings
190+ const isConfirmed = await confirm (
191+ 'Are you sure you want to clear all configuration settings? This action cannot be undone.'
192+ ) ;
193+
194+ if ( ! isConfirmed ) {
195+ logger . info ( 'Operation cancelled.' ) ;
196+ return ;
197+ }
198+
199+ // Clear all settings
200+ clearAllConfig ( ) ;
201+ logger . info ( 'All configuration settings have been cleared. Default values will be used.' ) ;
202+ return ;
203+ }
204+
156205 if ( ! argv . key ) {
157- logger . error ( 'Key is required for clear command' ) ;
206+ logger . error ( 'Key is required for clear command (or use --all to clear all settings) ' ) ;
158207 return ;
159208 }
160209
0 commit comments