@@ -53,10 +53,6 @@ impl Subcommand {
53
53
Completions { shell } => return Self :: completions ( * shell) ,
54
54
Init => return Self :: init ( config) ,
55
55
Man => return Self :: man ( ) ,
56
- Run {
57
- arguments,
58
- overrides,
59
- } => return Self :: run ( config, loader, arguments, overrides) ,
60
56
_ => { }
61
57
}
62
58
@@ -70,6 +66,10 @@ impl Subcommand {
70
66
let justfile = & compilation. justfile ;
71
67
72
68
match self {
69
+ Run {
70
+ arguments,
71
+ overrides,
72
+ } => Self :: run ( config, loader, search, arguments, overrides) ?,
73
73
Choose { overrides, chooser } => {
74
74
Self :: choose ( config, justfile, & search, overrides, chooser. as_deref ( ) ) ?;
75
75
}
@@ -83,7 +83,7 @@ impl Subcommand {
83
83
Show { path } => Self :: show ( config, justfile, path) ?,
84
84
Summary => Self :: summary ( config, justfile) ,
85
85
Variables => Self :: variables ( justfile) ,
86
- Changelog | Completions { .. } | Edit | Init | Man | Run { .. } => unreachable ! ( ) ,
86
+ Changelog | Completions { .. } | Edit | Init | Man => unreachable ! ( ) ,
87
87
}
88
88
89
89
Ok ( ( ) )
@@ -99,90 +99,57 @@ impl Subcommand {
99
99
fn run < ' src > (
100
100
config : & Config ,
101
101
loader : & ' src Loader ,
102
+ initial_search : Search ,
102
103
arguments : & [ String ] ,
103
104
overrides : & BTreeMap < String , String > ,
104
105
) -> RunResult < ' src > {
105
- if matches ! (
106
- config. search_config,
107
- SearchConfig :: FromInvocationDirectory | SearchConfig :: FromSearchDirectory { .. }
108
- ) {
109
- let starting_path = match & config. search_config {
110
- SearchConfig :: FromInvocationDirectory => config. invocation_directory . clone ( ) ,
111
- SearchConfig :: FromSearchDirectory { search_directory } => config
112
- . invocation_directory
113
- . join ( search_directory)
114
- . lexiclean ( ) ,
115
- _ => unreachable ! ( ) ,
116
- } ;
117
-
118
- let mut path = starting_path. clone ( ) ;
119
-
120
- let mut unknown_recipes_errors = None ;
121
-
122
- loop {
123
- let search = match Search :: find_next ( & path) {
124
- Err ( SearchError :: NotFound ) => match unknown_recipes_errors {
125
- Some ( err) => return Err ( err) ,
126
- None => return Err ( SearchError :: NotFound . into ( ) ) ,
127
- } ,
128
- Err ( err) => return Err ( err. into ( ) ) ,
129
- Ok ( search) => {
130
- if config. verbosity . loquacious ( ) && path != starting_path {
131
- eprintln ! (
132
- "Trying {}" ,
133
- starting_path
134
- . strip_prefix( path)
135
- . unwrap( )
136
- . components( )
137
- . map( |_| path:: Component :: ParentDir )
138
- . collect:: <PathBuf >( )
139
- . join( search. justfile. file_name( ) . unwrap( ) )
140
- . display( )
141
- ) ;
142
- }
143
- search
144
- }
145
- } ;
146
-
147
- match Self :: run_inner ( config, loader, arguments, overrides, & search) {
148
- Err ( ( err @ ( Error :: UnknownRecipe { .. } | Error :: UnknownSubmodule { .. } ) , true ) ) => {
149
- match search. justfile . parent ( ) . unwrap ( ) . parent ( ) {
150
- Some ( parent) => {
151
- unknown_recipes_errors. get_or_insert ( err) ;
152
- path = parent. into ( ) ;
153
- }
154
- None => return Err ( err) ,
106
+ let starting_path = initial_search
107
+ . justfile
108
+ . parent ( )
109
+ . as_ref ( )
110
+ . unwrap ( )
111
+ . lexiclean ( ) ;
112
+
113
+ let mut search = initial_search;
114
+
115
+ loop {
116
+ let compilation = Self :: compile ( config, loader, & search) ?;
117
+ let justfile = & compilation. justfile ;
118
+ let fallback = justfile. settings . fallback
119
+ && matches ! (
120
+ config. search_config,
121
+ SearchConfig :: FromInvocationDirectory | SearchConfig :: FromSearchDirectory { .. }
122
+ ) ;
123
+ let run_result = justfile. run ( config, & search, overrides, arguments) ;
124
+
125
+ match run_result {
126
+ Err ( err @ ( Error :: UnknownRecipe { .. } | Error :: UnknownSubmodule { .. } ) ) if fallback => {
127
+ let new_search = match search. search_parent_directory ( ) {
128
+ Ok ( s) => s,
129
+ Err ( _e) => {
130
+ return Err ( err) ;
155
131
}
132
+ } ;
133
+ let p = new_search. justfile . parent ( ) . unwrap ( ) ;
134
+ let new_path = starting_path
135
+ . strip_prefix ( p)
136
+ . unwrap ( )
137
+ . components ( )
138
+ . map ( |_| path:: Component :: ParentDir )
139
+ . collect :: < PathBuf > ( )
140
+ . join ( new_search. justfile . file_name ( ) . unwrap ( ) ) ;
141
+
142
+ search = new_search;
143
+
144
+ if config. verbosity . loquacious ( ) {
145
+ eprintln ! ( "Trying {}" , new_path. display( ) ) ;
156
146
}
157
- result => return result. map_err ( |( err, _fallback) | err) ,
158
147
}
148
+ result => return result,
159
149
}
160
- } else {
161
- Self :: run_inner (
162
- config,
163
- loader,
164
- arguments,
165
- overrides,
166
- & Search :: find ( & config. search_config , & config. invocation_directory ) ?,
167
- )
168
- . map_err ( |( err, _fallback) | err)
169
150
}
170
151
}
171
152
172
- fn run_inner < ' src > (
173
- config : & Config ,
174
- loader : & ' src Loader ,
175
- arguments : & [ String ] ,
176
- overrides : & BTreeMap < String , String > ,
177
- search : & Search ,
178
- ) -> Result < ( ) , ( Error < ' src > , bool ) > {
179
- let compilation = Self :: compile ( config, loader, search) . map_err ( |err| ( err, false ) ) ?;
180
- let justfile = & compilation. justfile ;
181
- justfile
182
- . run ( config, search, overrides, arguments)
183
- . map_err ( |err| ( err, justfile. settings . fallback ) )
184
- }
185
-
186
153
fn compile < ' src > (
187
154
config : & Config ,
188
155
loader : & ' src Loader ,
0 commit comments