mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 01:05:01 +02:00
Some error improvements (#659)
This commit is contained in:
@ -274,6 +274,33 @@ impl Signature {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn call_signature(&self) -> String {
|
||||
let mut one_liner = String::new();
|
||||
one_liner.push_str(&self.name);
|
||||
one_liner.push(' ');
|
||||
|
||||
for positional in &self.required_positional {
|
||||
one_liner.push_str(&get_positional_short_name(positional, true));
|
||||
}
|
||||
for positional in &self.optional_positional {
|
||||
one_liner.push_str(&get_positional_short_name(positional, false));
|
||||
}
|
||||
|
||||
if self.rest_positional.is_some() {
|
||||
one_liner.push_str("...args ");
|
||||
}
|
||||
|
||||
// if !self.subcommands.is_empty() {
|
||||
// one_liner.push_str("<subcommand> ");
|
||||
// }
|
||||
|
||||
if !self.named.is_empty() {
|
||||
one_liner.push_str("{flags} ");
|
||||
}
|
||||
|
||||
one_liner
|
||||
}
|
||||
|
||||
/// Get list of the short-hand flags
|
||||
pub fn get_shorts(&self) -> Vec<char> {
|
||||
self.named.iter().filter_map(|f| f.short).collect()
|
||||
@ -431,6 +458,25 @@ impl Command for Predeclaration {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_positional_short_name(arg: &PositionalArg, is_required: bool) -> String {
|
||||
match &arg.shape {
|
||||
SyntaxShape::Keyword(name, ..) => {
|
||||
if is_required {
|
||||
format!("{} <{}> ", String::from_utf8_lossy(name), arg.name)
|
||||
} else {
|
||||
format!("({} <{}>) ", String::from_utf8_lossy(name), arg.name)
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if is_required {
|
||||
format!("<{}> ", arg.name)
|
||||
} else {
|
||||
format!("({}) ", arg.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct BlockCommand {
|
||||
signature: Signature,
|
||||
|
@ -46,6 +46,15 @@ impl Span {
|
||||
pub fn contains(&self, pos: usize) -> bool {
|
||||
pos >= self.start && pos < self.end
|
||||
}
|
||||
|
||||
/// Point to the space just past this span, useful for missing
|
||||
/// values
|
||||
pub fn past(&self) -> Span {
|
||||
Span {
|
||||
start: self.end,
|
||||
end: self.end,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Used when you have a slice of spans of at least size 1
|
||||
|
Reference in New Issue
Block a user