Skip to content

Commit 765fa24

Browse files
committed
wip2 unified_includes
TODO -- can subs be in includes? not set up that way now but I think it should be TODO later -- detect include loops TODO later -- update tests?, fix ruby, remove old support
1 parent 825d9b3 commit 765fa24

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/core/config.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,22 @@ impl TabryConf {
179179
pub fn expand_args<'a>(
180180
&'a self,
181181
args: &'a [TabryArg],
182+
includes: &'a [String],
182183
) -> Box<dyn Iterator<Item = &TabryConcreteArg> + 'a> {
183184
let iter = args.iter().flat_map(|arg| match arg {
184185
TabryArg::TabryIncludeArg { include } => {
185186
// TODO: bubble up error instead of unwrap (use get_arg_include)
186187
let include = self.arg_includes.get(include).unwrap();
187-
self.expand_args(&include.args)
188+
self.expand_args(&include.args, &include.includes)
188189
}
189190
TabryArg::TabryConcreteArg(concrete_arg) => Box::new(std::iter::once(concrete_arg)),
190191
});
192+
let iter = iter.chain(
193+
includes.iter().flat_map(move |include| {
194+
let inc = self.arg_includes.get(include).unwrap();
195+
self.expand_args(&inc.args, &inc.includes)
196+
}),
197+
);
191198
Box::new(iter)
192199
}
193200
}

src/engine/options_finder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ impl OptionsFinder {
166166
}
167167

168168
fn add_options_subcommand_args(&self, res: &mut OptionsResults) -> Result<(), TabryConfError> {
169+
let current_sub = self.result.current_sub();
169170
let sub_args = self
170171
.result
171172
.config
172-
.expand_args(&self.result.current_sub().args)
173+
.expand_args(&current_sub.args, &current_sub.includes)
173174
.collect::<Vec<_>>();
174175

175176
if let Some(arg) = sub_args.get(self.result.state.args.len()) {

0 commit comments

Comments
 (0)