@@ -94,6 +94,7 @@ mod arg {
94
94
pub ( crate ) const DOTENV_PATH : & str = "DOTENV-PATH" ;
95
95
pub ( crate ) const DRY_RUN : & str = "DRY-RUN" ;
96
96
pub ( crate ) const DUMP_FORMAT : & str = "DUMP-FORMAT" ;
97
+ pub ( crate ) const GLOBAL_JUSTFILE : & str = "GLOBAL_JUSTFILE" ;
97
98
pub ( crate ) const HIGHLIGHT : & str = "HIGHLIGHT" ;
98
99
pub ( crate ) const JUSTFILE : & str = "JUSTFILE" ;
99
100
pub ( crate ) const LIST_HEADING : & str = "LIST-HEADING" ;
@@ -465,6 +466,15 @@ impl Config {
465
466
. action ( ArgAction :: Append )
466
467
. help ( "Overrides and recipe(s) to run, defaulting to the first recipe in the justfile" ) ,
467
468
)
469
+ . arg (
470
+ Arg :: new ( arg:: GLOBAL_JUSTFILE )
471
+ . action ( ArgAction :: SetTrue )
472
+ . long ( "global-justfile" )
473
+ . short ( 'g' )
474
+ . conflicts_with ( arg:: JUSTFILE )
475
+ . conflicts_with ( arg:: WORKING_DIRECTORY )
476
+ . help ( "Use global justfile" )
477
+ )
468
478
}
469
479
470
480
fn color_from_matches ( matches : & ArgMatches ) -> ConfigResult < Color > {
@@ -520,6 +530,39 @@ impl Config {
520
530
}
521
531
}
522
532
533
+ fn search_config ( matches : & ArgMatches , positional : & Positional ) -> ConfigResult < SearchConfig > {
534
+ if matches. get_flag ( arg:: GLOBAL_JUSTFILE ) {
535
+ return Ok ( SearchConfig :: GlobalJustfile ) ;
536
+ }
537
+
538
+ let justfile = matches. get_one :: < PathBuf > ( arg:: JUSTFILE ) . map ( Into :: into) ;
539
+
540
+ let working_directory = matches
541
+ . get_one :: < PathBuf > ( arg:: WORKING_DIRECTORY )
542
+ . map ( Into :: into) ;
543
+
544
+ if let Some ( search_directory) = positional. search_directory . as_ref ( ) . map ( PathBuf :: from) {
545
+ if justfile. is_some ( ) || working_directory. is_some ( ) {
546
+ return Err ( ConfigError :: SearchDirConflict ) ;
547
+ }
548
+ Ok ( SearchConfig :: FromSearchDirectory { search_directory } )
549
+ } else {
550
+ match ( justfile, working_directory) {
551
+ ( None , None ) => Ok ( SearchConfig :: FromInvocationDirectory ) ,
552
+ ( Some ( justfile) , None ) => Ok ( SearchConfig :: WithJustfile { justfile } ) ,
553
+ ( Some ( justfile) , Some ( working_directory) ) => {
554
+ Ok ( SearchConfig :: WithJustfileAndWorkingDirectory {
555
+ justfile,
556
+ working_directory,
557
+ } )
558
+ }
559
+ ( None , Some ( _) ) => Err ( ConfigError :: internal (
560
+ "--working-directory set without --justfile" ,
561
+ ) ) ,
562
+ }
563
+ }
564
+ }
565
+
523
566
pub ( crate ) fn from_matches ( matches : & ArgMatches ) -> ConfigResult < Self > {
524
567
let invocation_directory = env:: current_dir ( ) . context ( config_error:: CurrentDirContext ) ?;
525
568
@@ -545,39 +588,11 @@ impl Config {
545
588
. map ( |s| s. map ( String :: as_str) ) ,
546
589
) ;
547
590
548
- for ( name, value) in positional. overrides {
591
+ for ( name, value) in & positional. overrides {
549
592
overrides. insert ( name. clone ( ) , value. clone ( ) ) ;
550
593
}
551
594
552
- let search_config = {
553
- let justfile = matches. get_one :: < PathBuf > ( arg:: JUSTFILE ) . map ( Into :: into) ;
554
- let working_directory = matches
555
- . get_one :: < PathBuf > ( arg:: WORKING_DIRECTORY )
556
- . map ( Into :: into) ;
557
-
558
- if let Some ( search_directory) = positional. search_directory . map ( PathBuf :: from) {
559
- if justfile. is_some ( ) || working_directory. is_some ( ) {
560
- return Err ( ConfigError :: SearchDirConflict ) ;
561
- }
562
- SearchConfig :: FromSearchDirectory { search_directory }
563
- } else {
564
- match ( justfile, working_directory) {
565
- ( None , None ) => SearchConfig :: FromInvocationDirectory ,
566
- ( Some ( justfile) , None ) => SearchConfig :: WithJustfile { justfile } ,
567
- ( Some ( justfile) , Some ( working_directory) ) => {
568
- SearchConfig :: WithJustfileAndWorkingDirectory {
569
- justfile,
570
- working_directory,
571
- }
572
- }
573
- ( None , Some ( _) ) => {
574
- return Err ( ConfigError :: internal (
575
- "--working-directory set without --justfile" ,
576
- ) )
577
- }
578
- }
579
- }
580
- } ;
595
+ let search_config = Self :: search_config ( matches, & positional) ?;
581
596
582
597
for subcommand in cmd:: ARGLESS {
583
598
if matches. get_flag ( subcommand) {
0 commit comments