Skip to content

Commit 8a7770c

Browse files
committed
fix: version and completions cmd in non cargo directory
Sometimes `version` and `completions` subcommands are to run in a directory that is not necessarily a Cargo project, for example, an IDE plugin to check if `cargo-mutants` is installed or a shell script to install completion for a dev env setup. This commit allows both subcommands run inside a non Cargo project directory.
1 parent bdea66e commit 8a7770c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/main.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,19 @@ fn main() -> Result<()> {
187187

188188
let options = Options::try_from(&args)?;
189189
// dbg!(&options);
190-
let source_path = args.dir.unwrap_or_else(|| Utf8Path::new(".").to_owned());
191-
let source_tree = CargoSourceTree::open(&source_path)?;
192-
interrupt::install_handler();
190+
193191
if args.version {
194192
println!("{} {}", NAME, VERSION);
193+
return Ok(())
195194
} else if let Some(shell) = args.completions {
196195
generate(shell, &mut Cargo::command(), "cargo", &mut io::stdout());
197-
} else if args.list_files {
196+
return Ok(())
197+
}
198+
199+
let source_path = args.dir.unwrap_or_else(|| Utf8Path::new(".").to_owned());
200+
let source_tree = CargoSourceTree::open(&source_path)?;
201+
interrupt::install_handler();
202+
if args.list_files {
198203
list_files(&source_tree, &options, args.json)?;
199204
} else if args.list {
200205
let mutants = discover_mutants(&source_tree, &options)?;

0 commit comments

Comments
 (0)