11//! `run` subcommand
22
3- use crate :: config:: { BranchName , Config , PullRequest } ;
3+ use crate :: config:: { self , BranchName , Config , PullRequest } ;
44use std:: ffi:: OsString ;
55use std:: fs:: { self , File } ;
66use std:: io:: Write as _;
@@ -12,9 +12,7 @@ use colored::Colorize as _;
1212use crate :: git_high_level;
1313use crate :: github_api:: { self , Branch , Remote , RemoteBranch } ;
1414use crate :: utils:: { display_link, with_uuid} ;
15- use crate :: {
16- CONFIG_FILE , CONFIG_FILE_PATH , CONFIG_PATH , CONFIG_ROOT , commands, confirm_prompt, git,
17- } ;
15+ use crate :: { commands, confirm_prompt, git} ;
1816
1917/// Backup for a file
2018struct FileBackup {
@@ -26,10 +24,13 @@ struct FileBackup {
2624
2725/// Run patchy, if `yes` then there will be no prompt
2826pub async fn run ( yes : bool ) -> anyhow:: Result < ( ) > {
29- let root = CONFIG_ROOT . as_str ( ) ;
27+ let root = config :: ROOT . as_str ( ) ;
3028
31- let Ok ( config_string) = fs:: read_to_string ( & * CONFIG_FILE_PATH ) else {
32- log:: error!( "Could not find configuration file at {root}/{CONFIG_FILE}" ) ;
29+ let Ok ( config_string) = fs:: read_to_string ( & * config:: FILE_PATH ) else {
30+ log:: error!(
31+ "Could not find configuration file at {root}/{}" ,
32+ config:: FILE
33+ ) ;
3334
3435 // We don't want to have *any* sort of prompt when using the -y flag since that
3536 // would be problematic in scripts
@@ -47,13 +48,16 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
4748 return Ok ( ( ) ) ;
4849 } ;
4950
50- log:: trace!( "Using configuration file {}" , CONFIG_FILE_PATH . display( ) ) ;
51+ log:: trace!( "Using configuration file {}" , config :: FILE_PATH . display( ) ) ;
5152
5253 let config = toml:: from_str :: < Config > ( & config_string) . map_err ( |err| {
53- anyhow ! ( "Could not parse `{root}/{CONFIG_FILE}` configuration file:\n {err}" , )
54+ anyhow ! (
55+ "Could not parse `{root}/{}` configuration file:\n {err}" ,
56+ config:: FILE
57+ )
5458 } ) ?;
5559
56- let crate :: config:: Branch {
60+ let config:: Branch {
5761 name : remote_branch,
5862 commit,
5963 } = config. remote_branch ;
@@ -70,10 +74,10 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
7074
7175 // --- Backup all files in the `.patchy` config directory
7276
73- let config_files = fs:: read_dir ( & * CONFIG_PATH ) . map_err ( |err| {
77+ let config_files = fs:: read_dir ( & * config :: PATH ) . map_err ( |err| {
7478 anyhow ! (
7579 "Failed to read files in directory `{}`:\n {err}" ,
76- & CONFIG_PATH . display( )
80+ & config :: PATH . display( )
7781 )
7882 } ) ?;
7983
@@ -211,15 +215,18 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
211215 }
212216 }
213217
214- if let Err ( err) = fs:: create_dir_all ( git:: ROOT . join ( CONFIG_ROOT . as_str ( ) ) ) {
218+ if let Err ( err) = fs:: create_dir_all ( git:: ROOT . join ( config :: ROOT . as_str ( ) ) ) {
215219 git:: checkout ( & previous_branch) ?;
216220
217221 git:: delete_remote_and_branch (
218222 & info. remote . local_remote_alias ,
219223 & info. branch . local_branch_name ,
220224 ) ?;
221225
222- bail ! ( "Could not create directory {}\n {err}" , CONFIG_ROOT . as_str( ) ) ;
226+ bail ! (
227+ "Could not create directory {}\n {err}" ,
228+ config:: ROOT . as_str( )
229+ ) ;
223230 }
224231
225232 // Restore all the backup files
@@ -228,7 +235,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
228235 filename, contents, ..
229236 } in & backed_up_files
230237 {
231- let path = git:: ROOT . join ( PathBuf :: from ( CONFIG_ROOT . as_str ( ) ) . join ( filename) ) ;
238+ let path = git:: ROOT . join ( PathBuf :: from ( config :: ROOT . as_str ( ) ) . join ( filename) ) ;
232239 let mut file =
233240 File :: create ( & path) . map_err ( |err| anyhow ! ( "failed to restore backup: {err}" ) ) ?;
234241
@@ -239,7 +246,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
239246
240247 for patch in config. patches {
241248 let file_name = git:: ROOT
242- . join ( CONFIG_ROOT . as_str ( ) )
249+ . join ( config :: ROOT . as_str ( ) )
243250 . join ( format ! ( "{patch}.patch" ) ) ;
244251
245252 if !file_name. exists ( ) {
@@ -265,7 +272,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
265272 ) ;
266273 }
267274
268- git:: add ( CONFIG_ROOT . as_str ( ) ) ?;
275+ git:: add ( config :: ROOT . as_str ( ) ) ?;
269276 git:: commit ( "restore configuration files" ) ?;
270277
271278 let temporary_branch = with_uuid ( "temp-branch" ) ;
0 commit comments