mirror of
https://github.com/nushell/nushell.git
synced 2025-08-01 02:20:37 +02:00
* Begin allowing comments and multiline scripts. * clippy * Finish moving to groups. Test pass * Keep going * WIP * WIP * BROKEN WIP * WIP * WIP * Fix more tests * WIP: alias starts working * Broken WIP * Broken WIP * Variables begin to work * captures start working * A little better but needs fixed scope * Shorthand env setting * Update main merge * Broken WIP * WIP * custom command parsing * Custom commands start working * Fix coloring and parsing of block * Almost there * Add some tests * Add more param types * Bump version * Fix benchmark * Fix stuff
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::prelude::*;
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue};
|
|
use nu_source::Tagged;
|
|
use std::path::PathBuf;
|
|
|
|
pub struct SubCommand;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct LoadArgs {
|
|
load: Tagged<PathBuf>,
|
|
}
|
|
|
|
#[async_trait]
|
|
impl WholeStreamCommand for SubCommand {
|
|
fn name(&self) -> &str {
|
|
"config load"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("config load").required(
|
|
"load",
|
|
SyntaxShape::Path,
|
|
"Path to load the config from",
|
|
)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Loads the config from the path given"
|
|
}
|
|
|
|
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
set(args).await
|
|
}
|
|
}
|
|
|
|
pub async fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
let name = args.call_info.name_tag.clone();
|
|
let name_span = args.call_info.name_tag.clone();
|
|
let (LoadArgs { load }, _) = args.process().await?;
|
|
|
|
let configuration = load.item().clone();
|
|
|
|
let result = nu_data::config::read(name_span, &Some(configuration))?;
|
|
|
|
Ok(futures::stream::iter(vec![ReturnSuccess::value(
|
|
UntaggedValue::Row(result.into()).into_value(name),
|
|
)])
|
|
.to_output_stream())
|
|
}
|