1
1
//! `run` subcommand
2
2
3
+ use crate :: cli:: Confirm ;
3
4
use crate :: config:: { self , BranchName , Config , PrNumber , PullRequest } ;
4
5
use anyhow:: Result ;
5
6
use std:: fs;
@@ -12,7 +13,7 @@ use crate::utils::{format_pr, format_url, with_uuid};
12
13
use crate :: { commands, confirm_prompt, git} ;
13
14
14
15
/// Run patchy, if `yes` then there will be no prompt
15
- pub async fn run ( yes : bool , use_gh_cli : bool ) -> Result < ( ) > {
16
+ pub async fn run ( confirm : Option < Confirm > , use_gh_cli : bool ) -> Result < ( ) > {
16
17
let root = config:: ROOT . as_str ( ) ;
17
18
18
19
let Ok ( config_string) = fs:: read_to_string ( & * config:: FILE_PATH ) else {
@@ -21,14 +22,16 @@ pub async fn run(yes: bool, use_gh_cli: bool) -> Result<()> {
21
22
config:: FILE
22
23
) ;
23
24
24
- // We don't want to have *any* sort of prompt when using the -y flag since that
25
- // would be problematic in scripts
26
- if !yes && confirm_prompt ! ( "Would you like us to run `patchy init` to initialize it?" , ) {
27
- commands:: init ( false ) ?;
28
- } else if yes {
29
- log:: info!( "You can create it with `patchy init`" , ) ;
25
+ let init_file = match confirm {
26
+ Some ( Confirm :: Yes ) => true ,
27
+ Some ( Confirm :: No ) => false ,
28
+ None => confirm_prompt ! ( "Would you like us to run `patchy init` to initialize it?" , ) ,
29
+ } ;
30
+
31
+ if init_file {
32
+ commands:: init ( Some ( Confirm :: Yes ) ) ?;
30
33
} else {
31
- // user said "no" in the prompt, so we don't do any initializing
34
+ log :: info! ( "You can create it with `patchy init`" , ) ;
32
35
}
33
36
34
37
// We don't want to read the default configuration file as config_string. Since
@@ -243,20 +246,17 @@ pub async fn run(yes: bool, use_gh_cli: bool) -> Result<()> {
243
246
& info. branch . local_branch_name ,
244
247
) ?;
245
248
246
- if yes
247
- || confirm_prompt ! (
249
+ let overwrite_branch = match confirm {
250
+ Some ( Confirm :: Yes ) => true ,
251
+ Some ( Confirm :: No ) => false ,
252
+ None => confirm_prompt ! (
248
253
"Overwrite branch {}? This is irreversible." ,
249
254
config. local_branch. as_ref( ) . cyan( )
250
- )
251
- {
255
+ ) ,
256
+ } ;
257
+
258
+ if overwrite_branch {
252
259
git:: rename_branch ( & temporary_branch, config. local_branch . as_ref ( ) ) ?;
253
- if yes {
254
- log:: info!(
255
- "Automatically overwrote branch {} since you supplied the {} flag" ,
256
- config. local_branch. as_ref( ) . cyan( ) ,
257
- "--yes" . bright_magenta( )
258
- ) ;
259
- }
260
260
log:: info!( "Success!" ) ;
261
261
return Ok ( ( ) ) ;
262
262
}
0 commit comments