We split off the evaluation engine part of nu-cli into its own crate. This helps improve build times for nu-cli by 17% in my tests. It also helps us see a bit better what's the core engine portion vs the part specific to the interactive CLI piece. There's more than can be done here, but I think it's a good start in the right direction.
69 lines
1.8 KiB
Rust
69 lines
1.8 KiB
Rust
use crate::prelude::*;
|
|
use nu_engine::WholeStreamCommand;
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::{ColumnPath, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
|
|
|
pub struct SubCommand;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct GetArgs {
|
|
path: ColumnPath,
|
|
}
|
|
|
|
#[async_trait]
|
|
impl WholeStreamCommand for SubCommand {
|
|
fn name(&self) -> &str {
|
|
"config get"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("config get").required(
|
|
"get",
|
|
SyntaxShape::ColumnPath,
|
|
"value to get from the config",
|
|
)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Gets a value from the config"
|
|
}
|
|
|
|
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
get(args).await
|
|
}
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
vec![Example {
|
|
description: "Get the current startup commands",
|
|
example: "config get startup",
|
|
result: None,
|
|
}]
|
|
}
|
|
}
|
|
|
|
pub async fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
let name_tag = args.call_info.name_tag.clone();
|
|
let (GetArgs { path }, _) = args.process().await?;
|
|
|
|
// NOTE: None because we are not loading a new config file, we just want to read from the
|
|
// existing config
|
|
let result = UntaggedValue::row(nu_data::config::read(&name_tag, &None)?).into_value(&name_tag);
|
|
|
|
let value = crate::commands::get::get_column_path(&path, &result)?;
|
|
|
|
Ok(match value {
|
|
Value {
|
|
value: UntaggedValue::Table(list),
|
|
..
|
|
} => {
|
|
let list: Vec<_> = list
|
|
.iter()
|
|
.map(|x| ReturnSuccess::value(x.clone()))
|
|
.collect();
|
|
|
|
futures::stream::iter(list).to_output_stream()
|
|
}
|
|
x => OutputStream::one(ReturnSuccess::value(x)),
|
|
})
|
|
}
|