forked from extern/nushell
moved commands
This commit is contained in:
51
crates/nu-command/src/env/let_env.rs
vendored
Normal file
51
crates/nu-command/src/env/let_env.rs
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
use nu_engine::eval_expression;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EvaluationContext};
|
||||
use nu_protocol::{Signature, SyntaxShape, Value};
|
||||
|
||||
pub struct LetEnv;
|
||||
|
||||
impl Command for LetEnv {
|
||||
fn name(&self) -> &str {
|
||||
"let-env"
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Create an environment variable and give it a value."
|
||||
}
|
||||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("let-env")
|
||||
.required("var_name", SyntaxShape::String, "variable name")
|
||||
.required(
|
||||
"initial_value",
|
||||
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::String)),
|
||||
"equals sign followed by value",
|
||||
)
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
context: &EvaluationContext,
|
||||
call: &Call,
|
||||
_input: Value,
|
||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
let env_var = call.positional[0]
|
||||
.as_string()
|
||||
.expect("internal error: missing variable");
|
||||
|
||||
let keyword_expr = call.positional[1]
|
||||
.as_keyword()
|
||||
.expect("internal error: missing keyword");
|
||||
|
||||
let rhs = eval_expression(context, keyword_expr)?;
|
||||
let rhs = rhs.as_string()?;
|
||||
|
||||
//println!("Adding: {:?} to {}", rhs, var_id);
|
||||
|
||||
context.add_env_var(env_var, rhs);
|
||||
Ok(Value::Nothing {
|
||||
span: call.positional[0].span,
|
||||
})
|
||||
}
|
||||
}
|
3
crates/nu-command/src/env/mod.rs
vendored
Normal file
3
crates/nu-command/src/env/mod.rs
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
mod let_env;
|
||||
|
||||
pub use let_env::LetEnv;
|
Reference in New Issue
Block a user