mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 15:13:01 +01:00
Touchups to external values
This commit is contained in:
parent
bec9fd2d2b
commit
b4eb32f1db
@ -240,15 +240,11 @@ impl ExternalCommand {
|
||||
span = Some(arg.span);
|
||||
}
|
||||
}
|
||||
if let Some(span) = span {
|
||||
return Err(ShellError::labeled_error(
|
||||
"External $it needs string data",
|
||||
"given object instead of string data",
|
||||
span,
|
||||
));
|
||||
} else {
|
||||
return Err(ShellError::string("Error: $it needs string data"));
|
||||
}
|
||||
return Err(ShellError::maybe_labeled_error(
|
||||
"External $it needs string data",
|
||||
"given object instead of string data",
|
||||
span,
|
||||
));
|
||||
}
|
||||
if !first {
|
||||
new_arg_string.push_str("&&");
|
||||
|
@ -291,7 +291,12 @@ impl Value {
|
||||
|
||||
crate fn as_string(&self) -> Result<String, ShellError> {
|
||||
match self {
|
||||
Value::Primitive(Primitive::String(s)) => Ok(s.clone()),
|
||||
Value::Primitive(Primitive::String(x)) => Ok(format!("{}", x)),
|
||||
Value::Primitive(Primitive::Boolean(x)) => Ok(format!("{}", x)),
|
||||
Value::Primitive(Primitive::Float(x)) => Ok(format!("{}", x.into_inner())),
|
||||
Value::Primitive(Primitive::Int(x)) => Ok(format!("{}", x)),
|
||||
Value::Primitive(Primitive::Bytes(x)) => Ok(format!("{}", x)),
|
||||
//Value::Primitive(Primitive::String(s)) => Ok(s.clone()),
|
||||
// TODO: this should definitely be more general with better errors
|
||||
other => Err(ShellError::string(format!(
|
||||
"Expected string, got {:?}",
|
||||
|
1
tests/external_num.out
Normal file
1
tests/external_num.out
Normal file
@ -0,0 +1 @@
|
||||
10
|
3
tests/external_num.txt
Normal file
3
tests/external_num.txt
Normal file
@ -0,0 +1,3 @@
|
||||
cd tests
|
||||
open test.json | get glossary.GlossDiv.GlossList.GlossEntry.Height | echo $it
|
||||
exit
|
@ -1,20 +1,24 @@
|
||||
{
|
||||
"glossary": {
|
||||
"title": "example glossary",
|
||||
"GlossDiv": {
|
||||
"GlossDiv": {
|
||||
"title": "S",
|
||||
"GlossList": {
|
||||
"GlossList": {
|
||||
"GlossEntry": {
|
||||
"ID": "SGML",
|
||||
"SortAs": "SGML",
|
||||
"GlossTerm": "Standard Generalized Markup Language",
|
||||
"Acronym": "SGML",
|
||||
"Abbrev": "ISO 8879:1986",
|
||||
"GlossDef": {
|
||||
"SortAs": "SGML",
|
||||
"GlossTerm": "Standard Generalized Markup Language",
|
||||
"Acronym": "SGML",
|
||||
"Abbrev": "ISO 8879:1986",
|
||||
"Height": 10,
|
||||
"GlossDef": {
|
||||
"para": "A meta-markup language, used to create markup languages such as DocBook.",
|
||||
"GlossSeeAlso": ["GML", "XML"]
|
||||
"GlossSeeAlso": [
|
||||
"GML",
|
||||
"XML"
|
||||
]
|
||||
},
|
||||
"GlossSee": "markup"
|
||||
"GlossSee": "markup"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,4 +101,10 @@ mod tests {
|
||||
fn lines() {
|
||||
test_helper("lines");
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn external_num() {
|
||||
test_helper("external_num");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user