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);
|
span = Some(arg.span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(span) = span {
|
return Err(ShellError::maybe_labeled_error(
|
||||||
return Err(ShellError::labeled_error(
|
|
||||||
"External $it needs string data",
|
"External $it needs string data",
|
||||||
"given object instead of string data",
|
"given object instead of string data",
|
||||||
span,
|
span,
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
return Err(ShellError::string("Error: $it needs string data"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !first {
|
if !first {
|
||||||
new_arg_string.push_str("&&");
|
new_arg_string.push_str("&&");
|
||||||
|
@ -291,7 +291,12 @@ impl Value {
|
|||||||
|
|
||||||
crate fn as_string(&self) -> Result<String, ShellError> {
|
crate fn as_string(&self) -> Result<String, ShellError> {
|
||||||
match self {
|
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
|
// TODO: this should definitely be more general with better errors
|
||||||
other => Err(ShellError::string(format!(
|
other => Err(ShellError::string(format!(
|
||||||
"Expected string, got {:?}",
|
"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
|
@ -10,9 +10,13 @@
|
|||||||
"GlossTerm": "Standard Generalized Markup Language",
|
"GlossTerm": "Standard Generalized Markup Language",
|
||||||
"Acronym": "SGML",
|
"Acronym": "SGML",
|
||||||
"Abbrev": "ISO 8879:1986",
|
"Abbrev": "ISO 8879:1986",
|
||||||
|
"Height": 10,
|
||||||
"GlossDef": {
|
"GlossDef": {
|
||||||
"para": "A meta-markup language, used to create markup languages such as DocBook.",
|
"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() {
|
fn lines() {
|
||||||
test_helper("lines");
|
test_helper("lines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn external_num() {
|
||||||
|
test_helper("external_num");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user