@@ -97,6 +97,14 @@ fn get_subcommands() -> Vec<Command> {
9797 . action( ArgAction :: SetTrue )
9898 . conflicts_with( "identity" )
9999 . required_unless_present( "identity" ) ,
100+ ) . arg(
101+ Arg :: new( "force" )
102+ . long( "force" )
103+ . help( "Removes all identities without prompting (for CI usage)" )
104+ . action( ArgAction :: SetTrue )
105+ . requires( "all" )
106+ . conflicts_with( "identity" )
107+ . required_unless_present( "identity" ) ,
100108 ) ,
101109 Command :: new( "token" ) . about( "Print the token for an identity" ) . arg(
102110 Arg :: new( "identity" )
@@ -211,6 +219,7 @@ async fn exec_init_default(mut config: Config, args: &ArgMatches) -> Result<(),
211219/// Executes the `identity remove` command which removes an identity from the config.
212220async fn exec_remove ( mut config : Config , args : & ArgMatches ) -> Result < ( ) , anyhow:: Error > {
213221 let identity_or_name = args. get_one :: < String > ( "identity" ) ;
222+ let force = args. get_flag ( "force" ) ;
214223
215224 if let Some ( identity_or_name) = identity_or_name {
216225 let ic = if is_hex_identity ( identity_or_name) {
@@ -229,23 +238,26 @@ async fn exec_remove(mut config: Config, args: &ArgMatches) -> Result<(), anyhow
229238 return Ok ( ( ) ) ;
230239 }
231240
232- print ! ( "Are you sure you want to remove all identities? (y/n) " ) ;
233- std:: io:: stdout ( ) . flush ( ) ?;
234-
235241 let mut input = String :: new ( ) ;
236- std:: io:: stdin ( ) . read_line ( & mut input) ?;
237- if input. trim ( ) == "y" {
238- let identity_count = config. identity_configs ( ) . len ( ) ;
239- config. delete_all_identity_configs ( ) ;
240- config. save ( ) ;
241- println ! (
242- " {} {} removed." ,
243- identity_count,
244- if identity_count > 1 { "identities" } else { "identity" }
245- ) ;
246- } else {
247- println ! ( " Aborted" ) ;
242+ if !force {
243+ print ! ( "Are you sure you want to remove all identities? (y/n) " ) ;
244+ std:: io:: stdout ( ) . flush ( ) ?;
245+ std:: io:: stdin ( ) . read_line ( & mut input) ?;
246+
247+ if input. trim ( ) != "y" {
248+ println ! ( " Aborted" ) ;
249+ return Ok ( ( ) ) ;
250+ }
248251 }
252+
253+ let identity_count = config. identity_configs ( ) . len ( ) ;
254+ config. delete_all_identity_configs ( ) ;
255+ config. save ( ) ;
256+ println ! (
257+ " {} {} removed." ,
258+ identity_count,
259+ if identity_count > 1 { "identities" } else { "identity" }
260+ ) ;
249261 }
250262 Ok ( ( ) )
251263}
0 commit comments