mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 08:26:22 +02:00
@ -35,7 +35,6 @@ impl WholeStreamCommand for Command {
|
||||
ctrl_c: args.ctrl_c,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
raw_input: args.raw_input,
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ pub(crate) async fn run_internal_command(
|
||||
.then(move |item| {
|
||||
let head = head.clone();
|
||||
let command = command.clone();
|
||||
let mut context = context.clone();
|
||||
let context = context.clone();
|
||||
async move {
|
||||
match item {
|
||||
Ok(ReturnSuccess::Action(action)) => match action {
|
||||
@ -188,6 +188,29 @@ pub(crate) async fn run_internal_command(
|
||||
context.scope.add_env_var(name, value);
|
||||
InputStream::from_stream(futures::stream::iter(vec![]))
|
||||
}
|
||||
CommandAction::SourceScript(filename) => {
|
||||
let contents = std::fs::read_to_string(&filename);
|
||||
if let Ok(contents) = contents {
|
||||
let result = crate::cli::run_script_standalone(
|
||||
contents, true, &context, false,
|
||||
)
|
||||
.await;
|
||||
|
||||
if let Err(err) = result {
|
||||
return InputStream::one(
|
||||
UntaggedValue::Error(err.into()).into_untagged_value(),
|
||||
);
|
||||
}
|
||||
InputStream::from_stream(futures::stream::iter(vec![]))
|
||||
} else {
|
||||
InputStream::one(
|
||||
UntaggedValue::Error(ShellError::untagged_runtime_error(
|
||||
format!("could not source '{}'", filename),
|
||||
))
|
||||
.into_untagged_value(),
|
||||
)
|
||||
}
|
||||
}
|
||||
CommandAction::AddPlugins(path) => {
|
||||
match crate::plugin::scan(vec![std::path::PathBuf::from(path)]) {
|
||||
Ok(plugins) => {
|
||||
|
@ -43,7 +43,6 @@ pub struct CommandArgs {
|
||||
pub call_info: UnevaluatedCallInfo,
|
||||
pub scope: Scope,
|
||||
pub input: InputStream,
|
||||
pub raw_input: String,
|
||||
}
|
||||
|
||||
#[derive(Getters, Clone)]
|
||||
@ -67,7 +66,6 @@ impl RawCommandArgs {
|
||||
call_info: self.call_info,
|
||||
scope: self.scope,
|
||||
input: input.into(),
|
||||
raw_input: String::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,7 +114,6 @@ pub struct RunnableContext {
|
||||
pub current_errors: Arc<Mutex<Vec<ShellError>>>,
|
||||
pub scope: Scope,
|
||||
pub name: Tag,
|
||||
pub raw_input: String,
|
||||
}
|
||||
|
||||
impl RunnableContext {
|
||||
|
@ -38,7 +38,6 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctrl_c: args.ctrl_c,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
raw_input: args.raw_input,
|
||||
},
|
||||
average,
|
||||
)
|
||||
|
@ -31,7 +31,6 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctrl_c: args.ctrl_c,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
raw_input: args.raw_input,
|
||||
},
|
||||
ceil_big_int,
|
||||
ceil_big_decimal,
|
||||
|
@ -31,7 +31,6 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctrl_c: args.ctrl_c,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
raw_input: args.raw_input,
|
||||
},
|
||||
floor_big_int,
|
||||
floor_big_decimal,
|
||||
|
@ -31,7 +31,6 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctrl_c: args.ctrl_c,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
raw_input: args.raw_input,
|
||||
},
|
||||
maximum,
|
||||
)
|
||||
|
@ -35,7 +35,6 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctrl_c: args.ctrl_c,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
raw_input: args.raw_input,
|
||||
},
|
||||
median,
|
||||
)
|
||||
|
@ -31,7 +31,6 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctrl_c: args.ctrl_c,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
raw_input: args.raw_input,
|
||||
},
|
||||
minimum,
|
||||
)
|
||||
|
@ -31,7 +31,6 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctrl_c: args.ctrl_c,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
raw_input: args.raw_input,
|
||||
},
|
||||
mode,
|
||||
)
|
||||
|
@ -34,7 +34,6 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctrl_c: args.ctrl_c,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
raw_input: args.raw_input,
|
||||
},
|
||||
product,
|
||||
)
|
||||
|
@ -35,7 +35,6 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctrl_c: args.ctrl_c,
|
||||
current_errors: args.current_errors,
|
||||
name: args.call_info.name_tag,
|
||||
raw_input: args.raw_input,
|
||||
},
|
||||
summation,
|
||||
)
|
||||
|
@ -88,7 +88,6 @@ impl WholeStreamCommand for RunExternalCommand {
|
||||
ctrl_c: args.ctrl_c.clone(),
|
||||
current_errors: Arc::new(Mutex::new(vec![])),
|
||||
windows_drives_previous_cwd: Arc::new(Mutex::new(std::collections::HashMap::new())),
|
||||
raw_input: String::default(),
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -165,7 +165,7 @@ async fn save(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let host = raw_args.host.clone();
|
||||
let ctrl_c = raw_args.ctrl_c.clone();
|
||||
let current_errors = raw_args.current_errors.clone();
|
||||
let mut shell_manager = raw_args.shell_manager.clone();
|
||||
let shell_manager = raw_args.shell_manager.clone();
|
||||
|
||||
let head = raw_args.call_info.args.head.clone();
|
||||
let (
|
||||
|
48
crates/nu-cli/src/commands/source.rs
Normal file
48
crates/nu-cli/src/commands/source.rs
Normal file
@ -0,0 +1,48 @@
|
||||
use crate::commands::WholeStreamCommand;
|
||||
use crate::prelude::*;
|
||||
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{CommandAction, ReturnSuccess, Signature, SyntaxShape};
|
||||
use nu_source::Tagged;
|
||||
|
||||
pub struct Source;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SourceArgs {
|
||||
pub filename: Tagged<String>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl WholeStreamCommand for Source {
|
||||
fn name(&self) -> &str {
|
||||
"source"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("source").required(
|
||||
"filename",
|
||||
SyntaxShape::String,
|
||||
"the filepath to the script file to source",
|
||||
)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Runs a script file in the current context."
|
||||
}
|
||||
|
||||
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
source(args).await
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn source(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let (SourceArgs { filename }, _) = args.process().await?;
|
||||
|
||||
Ok(OutputStream::one(ReturnSuccess::action(
|
||||
CommandAction::SourceScript(filename.item),
|
||||
)))
|
||||
}
|
Reference in New Issue
Block a user