mirror of
https://github.com/nushell/nushell.git
synced 2025-05-06 02:54:25 +02:00
* Specialize 'Context' to EvaluationContext and CompletionContext * Specialize 'Context' to EvaluationContext and CompletionContext * fmt
58 lines
1.4 KiB
Rust
58 lines
1.4 KiB
Rust
use crate::command_registry::CommandRegistry;
|
|
use crate::commands::WholeStreamCommand;
|
|
use crate::prelude::*;
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
|
|
|
pub struct SubCommand;
|
|
|
|
#[async_trait]
|
|
impl WholeStreamCommand for SubCommand {
|
|
fn name(&self) -> &str {
|
|
"config clear"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("config clear")
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"clear the config"
|
|
}
|
|
|
|
async fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
clear(args, registry).await
|
|
}
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
vec![Example {
|
|
description: "Clear the config (be careful!)",
|
|
example: "config clear",
|
|
result: None,
|
|
}]
|
|
}
|
|
}
|
|
|
|
pub async fn clear(
|
|
args: CommandArgs,
|
|
_registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
let name_span = args.call_info.name_tag.clone();
|
|
|
|
// NOTE: None because we are not loading a new config file, we just want to read from the
|
|
// existing config
|
|
let mut result = nu_data::config::read(name_span, &None)?;
|
|
|
|
result.clear();
|
|
|
|
config::write(&result, &None)?;
|
|
|
|
Ok(OutputStream::one(ReturnSuccess::value(
|
|
UntaggedValue::Row(result.into()).into_value(args.call_info.name_tag),
|
|
)))
|
|
}
|