Skip to content

Commit fac4245

Browse files
authored
Merge pull request #291 from blopker/feature/justfile
Fix --ast arg parsing for paths containing "codebook"
2 parents 2a29b55 + 849b07f commit fac4245

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

crates/codebook/src/main.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,20 @@ fn main() {
1717
.windows(2)
1818
.find(|w| w[0] == "--lang")
1919
.map(|w| w[1].as_str());
20-
let file_arg = args.iter().find(|a| {
21-
*a != "--ast" && *a != "--lang" && !a.starts_with("--") && !a.contains("codebook")
22-
});
20+
// Skip argv[0] and flag values: the file is the first positional arg.
21+
let mut file_arg = None;
22+
let mut iter = args.iter().skip(1);
23+
while let Some(arg) = iter.next() {
24+
if arg == "--lang" {
25+
iter.next();
26+
continue;
27+
}
28+
if arg.starts_with("--") {
29+
continue;
30+
}
31+
file_arg = Some(arg);
32+
break;
33+
}
2334
match file_arg {
2435
Some(path) => dump_ast(path, lang_override),
2536
None => eprintln!("Usage: codebook --ast <file> [--lang <language>]"),

0 commit comments

Comments
 (0)