mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 11:45:50 +02:00
let UnknownFlag
error list out available flags (#7443)
# Description Fixes #6773. ``` /home/gabriel/CodingProjects/nushell〉ls -r 12/12/2022 02:57:35 PM Error: nu::parser::unknown_flag (link) × The `ls` command doesn't have flag `-r`. ╭─[entry #1:1:1] 1 │ ls -r · ┬ · ╰── unknown flag ╰──── help: Available flags: --help(-h), --all(-a), --long(-l), --short-names(-s), --full-paths(-f), --du(-d), --directory(-D). Use `--help` for more information. ``` # User-Facing Changes Different error for unknown flag. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
@ -610,6 +610,37 @@ impl Signature {
|
||||
block_id,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn formatted_flags(self) -> String {
|
||||
if self.named.len() < 11 {
|
||||
let mut s = "Available flags:".to_string();
|
||||
for flag in self.named {
|
||||
if let Some(short) = flag.short {
|
||||
let _ = write!(s, " --{}(-{}),", flag.long, short);
|
||||
} else {
|
||||
let _ = write!(s, " --{},", flag.long);
|
||||
}
|
||||
}
|
||||
s.remove(s.len() - 1);
|
||||
let _ = write!(s, ". Use `--help` for more information.");
|
||||
s
|
||||
} else {
|
||||
let mut s = "Some available flags:".to_string();
|
||||
for flag in self.named {
|
||||
if let Some(short) = flag.short {
|
||||
let _ = write!(s, " --{}(-{}),", flag.long, short);
|
||||
} else {
|
||||
let _ = write!(s, " --{},", flag.long);
|
||||
}
|
||||
}
|
||||
s.remove(s.len() - 1);
|
||||
let _ = write!(
|
||||
s,
|
||||
"... Use `--help` for a full list of flags and more information."
|
||||
);
|
||||
s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
Reference in New Issue
Block a user