Skip to content

Commit

Permalink
fix(cli): Ensure we can run on files
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 5, 2021
1 parent 6e8f7cf commit 60fe94c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/bin/typos-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,14 @@ fn run_checks(
let mut errors_found = false;
for path in args.path.iter() {
let cwd = if path == std::path::Path::new("-") {
global_cwd.as_path()
global_cwd.clone()
} else if path.is_file() {
path.parent().unwrap()
let mut cwd = path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
cwd.pop();
cwd
} else {
path.as_path()
path.clone()
};
let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;

engine
.init_dir(&cwd)
Expand Down
7 changes: 7 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ fn test_stdin_correct() {
.write_stdin("Apropriate world");
cmd.assert().success().stdout("Appropriate world");
}

#[test]
fn test_file_failure() {
let mut cmd = Command::cargo_bin("typos").unwrap();
cmd.arg("README.md");
cmd.assert().code(2);
}

0 comments on commit 60fe94c

Please sign in to comment.