11//! `run` subcommand
22
3+ use crate :: cli:: Confirm ;
34use crate :: config:: { self , BranchName , Config , PrNumber , PullRequest } ;
45use anyhow:: Result ;
56use std:: fs;
@@ -12,7 +13,7 @@ use crate::utils::{format_pr, format_url, with_uuid};
1213use crate :: { commands, confirm_prompt, git} ;
1314
1415/// 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 < ( ) > {
1617 let root = config:: ROOT . as_str ( ) ;
1718
1819 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<()> {
2122 config:: FILE
2223 ) ;
2324
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 ) ) ?;
3033 } 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`" , ) ;
3235 }
3336
3437 // 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<()> {
243246 & info. branch . local_branch_name ,
244247 ) ?;
245248
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 ! (
248253 "Overwrite branch {}? This is irreversible." ,
249254 config. local_branch. as_ref( ) . cyan( )
250- )
251- {
255+ ) ,
256+ } ;
257+
258+ if overwrite_branch {
252259 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- }
260260 log:: info!( "Success!" ) ;
261261 return Ok ( ( ) ) ;
262262 }
0 commit comments