mirror of
https://github.com/nushell/nushell.git
synced 2025-05-02 09:04:30 +02:00
* move commands, futures.rs, script.rs, utils * move over maybe_print_errors * add nu_command crate references to nu_cli * in commands.rs open up to pub mod from pub(crate) * nu-cli, nu-command, and nu tests are now passing * cargo fmt * clean up nu-cli/src/prelude.rs * code cleanup * for some reason lex.rs was not formatted, may be causing my error * remove mod completion from lib.rs which was not being used along with quickcheck macros * add in allow unused imports * comment out one failing external test; comment out one failing internal test * revert commenting out failing tests; something else might be going on; someone with a windows machine should check and see what is going on with these failing windows tests * Update Cargo.toml Extend the optional features to nu-command Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
68 lines
1.7 KiB
Rust
68 lines
1.7 KiB
Rust
use crate::prelude::*;
|
|
use nu_engine::WholeStreamCommand;
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue};
|
|
use nu_source::Tagged;
|
|
|
|
pub struct SubCommand;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct RemoveArgs {
|
|
remove: Tagged<String>,
|
|
}
|
|
|
|
#[async_trait]
|
|
impl WholeStreamCommand for SubCommand {
|
|
fn name(&self) -> &str {
|
|
"config remove"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("config remove").required(
|
|
"remove",
|
|
SyntaxShape::Any,
|
|
"remove a value from the config",
|
|
)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Removes a value from the config"
|
|
}
|
|
|
|
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
remove(args).await
|
|
}
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
vec![Example {
|
|
description: "Remove the startup commands",
|
|
example: "config remove startup",
|
|
result: None,
|
|
}]
|
|
}
|
|
}
|
|
|
|
pub async fn remove(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
let name_span = args.call_info.name_tag.clone();
|
|
let (RemoveArgs { remove }, _) = args.process().await?;
|
|
|
|
let mut result = nu_data::config::read(name_span, &None)?;
|
|
|
|
let key = remove.to_string();
|
|
|
|
if result.contains_key(&key) {
|
|
result.swap_remove(&key);
|
|
config::write(&result, &None)?;
|
|
Ok(futures::stream::iter(vec![ReturnSuccess::value(
|
|
UntaggedValue::Row(result.into()).into_value(remove.tag()),
|
|
)])
|
|
.to_output_stream())
|
|
} else {
|
|
Err(ShellError::labeled_error(
|
|
"Key does not exist in config",
|
|
"key",
|
|
remove.tag(),
|
|
))
|
|
}
|
|
}
|