Add support for load-env (#752)

This commit is contained in:
JT
2022-01-15 18:50:11 -05:00
committed by GitHub
parent 75db4a75bc
commit b78924c777
8 changed files with 136 additions and 5 deletions

View File

@ -80,6 +80,9 @@ pub enum SyntaxShape {
/// A boolean value
Boolean,
/// A record value
Record,
/// A custom shape with custom completion logic
Custom(Box<SyntaxShape>, String),
}
@ -108,6 +111,7 @@ impl SyntaxShape {
SyntaxShape::Number => Type::Number,
SyntaxShape::Operator => Type::Unknown,
SyntaxShape::Range => Type::Unknown,
SyntaxShape::Record => Type::Record(vec![]), // FIXME: Add actual record type
SyntaxShape::RowCondition => Type::Bool,
SyntaxShape::Boolean => Type::Bool,
SyntaxShape::Signature => Type::Signature,
@ -138,6 +142,7 @@ impl Display for SyntaxShape {
SyntaxShape::Block(_) => write!(f, "block"),
SyntaxShape::Table => write!(f, "table"),
SyntaxShape::List(x) => write!(f, "list<{}>", x),
SyntaxShape::Record => write!(f, "record"),
SyntaxShape::Filesize => write!(f, "filesize"),
SyntaxShape::Duration => write!(f, "duration"),
SyntaxShape::Operator => write!(f, "operator"),

View File

@ -353,6 +353,20 @@ impl FromValue for Vec<Value> {
}
}
// A record
impl FromValue for (Vec<String>, Vec<Value>) {
fn from_value(v: &Value) -> Result<Self, ShellError> {
match v {
Value::Record { cols, vals, .. } => Ok((cols.clone(), vals.clone())),
v => Err(ShellError::CantConvert(
"Record".into(),
v.get_type().to_string(),
v.span()?,
)),
}
}
}
impl FromValue for CaptureBlock {
fn from_value(v: &Value) -> Result<Self, ShellError> {
match v {