mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-26 02:51:08 -05:00
Merge pull request #808 from epage/no
fix(cli): Improve error when args aren't present
This commit is contained in:
commit
c8189bf54a
3 changed files with 22 additions and 1 deletions
|
@ -139,7 +139,12 @@ fn run_type_list(args: &args::Args) -> proc_exit::ExitResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_checks(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 storage = typos_cli::policy::ConfigStorage::new();
|
||||||
let mut engine = typos_cli::policy::ConfigEngine::new(&storage);
|
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() {
|
} else if path.is_file() {
|
||||||
let mut cwd = path
|
let mut cwd = path
|
||||||
.canonicalize()
|
.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)?;
|
.with_code(proc_exit::sysexits::USAGE_ERR)?;
|
||||||
cwd.pop();
|
cwd.pop();
|
||||||
cwd
|
cwd
|
||||||
} else {
|
} else {
|
||||||
path.canonicalize()
|
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)?
|
.with_code(proc_exit::sysexits::USAGE_ERR)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
0
crates/typos-cli/tests/cmd/missing-arg.in/.keep
Normal file
0
crates/typos-cli/tests/cmd/missing-arg.in/.keep
Normal file
8
crates/typos-cli/tests/cmd/missing-arg.toml
Normal file
8
crates/typos-cli/tests/cmd/missing-arg.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
bin.name = "typos"
|
||||||
|
args = "foo"
|
||||||
|
status.code = 64
|
||||||
|
stdin = ""
|
||||||
|
# stdout doesn't have stable order
|
||||||
|
stderr = """
|
||||||
|
argument `foo` is not found
|
||||||
|
"""
|
Loading…
Reference in a new issue