mirror of
https://github.com/nushell/nushell.git
synced 2025-08-12 09:21:26 +02:00
Tests pass
This commit is contained in:
@ -1,17 +1,31 @@
|
||||
use crate::Text;
|
||||
use derive_new::new;
|
||||
use getset::Getters;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
#[derive(
|
||||
new, Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, Hash, Getters,
|
||||
)]
|
||||
#[derive(new, Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Deserialize, Hash, Getters)]
|
||||
#[get = "crate"]
|
||||
pub struct Spanned<T> {
|
||||
pub span: Span,
|
||||
pub item: T,
|
||||
}
|
||||
|
||||
impl<T: Serialize> Serialize for Spanned<T> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
self.item.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Spanned<T> {
|
||||
pub fn spanned(self, span: impl Into<Span>) -> Spanned<T> {
|
||||
Spanned::from_item(self.item, span.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SpannedItem: Sized {
|
||||
fn spanned(self, span: impl Into<Span>) -> Spanned<Self> {
|
||||
Spanned::from_item(self, span.into())
|
||||
|
@ -93,11 +93,11 @@ fn parse_command_tail(
|
||||
tail.move_to(pos);
|
||||
|
||||
if tail.at_end() {
|
||||
return Err(ShellError::ArgumentError {
|
||||
command: config.name().clone(),
|
||||
error: ArgumentError::MissingValueForName(name.to_string()),
|
||||
span: flag.span,
|
||||
});
|
||||
return Err(ShellError::argument_error(
|
||||
config.name.clone(),
|
||||
ArgumentError::MissingValueForName(name.to_string()),
|
||||
flag.span,
|
||||
));
|
||||
}
|
||||
|
||||
let expr = hir::baseline_parse_next_expr(
|
||||
@ -118,11 +118,11 @@ fn parse_command_tail(
|
||||
tail.move_to(pos);
|
||||
|
||||
if tail.at_end() {
|
||||
return Err(ShellError::ArgumentError {
|
||||
command: config.name().clone(),
|
||||
error: ArgumentError::MissingValueForName(name.to_string()),
|
||||
span: flag.span,
|
||||
});
|
||||
return Err(ShellError::argument_error(
|
||||
config.name().clone(),
|
||||
ArgumentError::MissingValueForName(name.to_string()),
|
||||
flag.span,
|
||||
));
|
||||
}
|
||||
|
||||
let expr = hir::baseline_parse_next_expr(
|
||||
@ -154,11 +154,11 @@ fn parse_command_tail(
|
||||
match arg {
|
||||
PositionalType::Mandatory(..) => {
|
||||
if tail.len() == 0 {
|
||||
return Err(ShellError::ArgumentError {
|
||||
command: config.name().clone(),
|
||||
error: ArgumentError::MissingMandatoryPositional(arg.name().to_string()),
|
||||
span: command_span,
|
||||
});
|
||||
return Err(ShellError::argument_error(
|
||||
config.name().clone(),
|
||||
ArgumentError::MissingMandatoryPositional(arg.name().to_string()),
|
||||
command_span,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,11 +215,11 @@ fn extract_mandatory(
|
||||
let flag = tokens.extract(|t| t.as_flag(name, source));
|
||||
|
||||
match flag {
|
||||
None => Err(ShellError::ArgumentError {
|
||||
command: config.name().clone(),
|
||||
error: ArgumentError::MissingMandatoryFlag(name.to_string()),
|
||||
None => Err(ShellError::argument_error(
|
||||
config.name().clone(),
|
||||
ArgumentError::MissingMandatoryFlag(name.to_string()),
|
||||
span,
|
||||
}),
|
||||
)),
|
||||
|
||||
Some((pos, flag)) => {
|
||||
tokens.remove(pos);
|
||||
|
@ -102,7 +102,7 @@ impl fmt::Debug for DebugPositional<'a> {
|
||||
None => write!(f, "None"),
|
||||
Some(positional) => f
|
||||
.debug_list()
|
||||
.entries(positional.iter().map(|p| p.item().debug()))
|
||||
.entries(positional.iter().map(|p| p.debug()))
|
||||
.finish(),
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,7 @@ impl fmt::Debug for DebugNamed<'a> {
|
||||
None => write!(f, "None"),
|
||||
Some(named) => f
|
||||
.debug_map()
|
||||
.entries(named.iter().map(|(k, v)| (k, v.item().debug())))
|
||||
.entries(named.iter().map(|(k, v)| (k, v.debug())))
|
||||
.finish(),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user