mirror of
https://github.com/nushell/nushell.git
synced 2025-05-09 17:32:59 +00:00
* Add ability to remove env variables Signed-off-by: nathom <nathanthomas707@gmail.com> * Implement unlet_env command Signed-off-by: nathom <nathanthomas707@gmail.com> * Update parameter description Signed-off-by: nathom <nathanthomas707@gmail.com> * Migrate to new filestructure Signed-off-by: nathom <nathanthomas707@gmail.com> * Added tests for unlet-env Signed-off-by: nathom <nathanthomas707@gmail.com> * Formatting Signed-off-by: nathom <nathanthomas707@gmail.com>
60 lines
1.4 KiB
Rust
60 lines
1.4 KiB
Rust
use crate::prelude::*;
|
|
use nu_engine::WholeStreamCommand;
|
|
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::{Signature, SyntaxShape};
|
|
use nu_source::Tagged;
|
|
|
|
pub struct UnletEnv;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct UnletEnvArgs {
|
|
pub name: Tagged<String>,
|
|
}
|
|
|
|
impl WholeStreamCommand for UnletEnv {
|
|
fn name(&self) -> &str {
|
|
"unlet-env"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("unlet-env").required(
|
|
"name",
|
|
SyntaxShape::String,
|
|
"the name of the environment variable",
|
|
)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Delete an environment variable."
|
|
}
|
|
|
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
|
unlet_env(args)
|
|
}
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
vec![Example {
|
|
description: "Remove the environment variable named FOO.",
|
|
example: "unlet-env FOO",
|
|
result: None,
|
|
}]
|
|
}
|
|
}
|
|
|
|
pub fn unlet_env(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
|
let ctx = &args.context;
|
|
|
|
let name: Tagged<String> = args.req(0)?;
|
|
|
|
if ctx.scope.remove_env_var(&name.item) == None {
|
|
return Err(ShellError::labeled_error(
|
|
"Not an environment variable. Run `echo $nu.env` to view the available variables.",
|
|
"not an environment variable",
|
|
name.span(),
|
|
));
|
|
}
|
|
|
|
Ok(ActionStream::empty())
|
|
}
|