From cfa18211007b4d7f148d4f6c9bc32ba579a9de76 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 21 Aug 2023 10:16:16 -0500 Subject: [PATCH 1/2] test(cli): Show no file error --- crates/typos-cli/tests/cmd/missing-arg.in/.keep | 0 crates/typos-cli/tests/cmd/missing-arg.toml | 8 ++++++++ 2 files changed, 8 insertions(+) create mode 100644 crates/typos-cli/tests/cmd/missing-arg.in/.keep create mode 100644 crates/typos-cli/tests/cmd/missing-arg.toml diff --git a/crates/typos-cli/tests/cmd/missing-arg.in/.keep b/crates/typos-cli/tests/cmd/missing-arg.in/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/crates/typos-cli/tests/cmd/missing-arg.toml b/crates/typos-cli/tests/cmd/missing-arg.toml new file mode 100644 index 000000000..cee0bc6bd --- /dev/null +++ b/crates/typos-cli/tests/cmd/missing-arg.toml @@ -0,0 +1,8 @@ +bin.name = "typos" +args = "foo" +status.code = 64 +stdin = "" +# stdout doesn't have stable order +stderr = """ +No such file or directory (os error 2) +""" From 8be21b28e717688d610db8da349026f45cadbfb1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 21 Aug 2023 10:20:16 -0500 Subject: [PATCH 2/2] fix(cli): Improve error when args aren't present --- crates/typos-cli/src/bin/typos-cli/main.rs | 15 ++++++++++++++- crates/typos-cli/tests/cmd/missing-arg.toml | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/typos-cli/src/bin/typos-cli/main.rs b/crates/typos-cli/src/bin/typos-cli/main.rs index 06adf9954..d7902fb8e 100644 --- a/crates/typos-cli/src/bin/typos-cli/main.rs +++ b/crates/typos-cli/src/bin/typos-cli/main.rs @@ -139,7 +139,12 @@ fn run_type_list(args: &args::Args) -> proc_exit::ExitResult { } fn run_checks(args: &args::Args) -> proc_exit::ExitResult { - let global_cwd = std::env::current_dir().to_sysexits()?; + let global_cwd = std::env::current_dir() + .map_err(|err| { + let kind = err.kind(); + std::io::Error::new(kind, "no current working directory".to_owned()) + }) + .to_sysexits()?; let storage = typos_cli::policy::ConfigStorage::new(); let mut engine = typos_cli::policy::ConfigEngine::new(&storage); @@ -162,11 +167,19 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult { } else if path.is_file() { let mut cwd = path .canonicalize() + .map_err(|err| { + let kind = err.kind(); + std::io::Error::new(kind, format!("argument `{}` is not found", path.display())) + }) .with_code(proc_exit::sysexits::USAGE_ERR)?; cwd.pop(); cwd } else { path.canonicalize() + .map_err(|err| { + let kind = err.kind(); + std::io::Error::new(kind, format!("argument `{}` is not found", path.display())) + }) .with_code(proc_exit::sysexits::USAGE_ERR)? }; diff --git a/crates/typos-cli/tests/cmd/missing-arg.toml b/crates/typos-cli/tests/cmd/missing-arg.toml index cee0bc6bd..ca60d1d18 100644 --- a/crates/typos-cli/tests/cmd/missing-arg.toml +++ b/crates/typos-cli/tests/cmd/missing-arg.toml @@ -4,5 +4,5 @@ status.code = 64 stdin = "" # stdout doesn't have stable order stderr = """ -No such file or directory (os error 2) +argument `foo` is not found """