mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
Add --execute option (#6302)
This commit is contained in:
parent
4bbdb73668
commit
df3b6d9d26
2 changed files with 25 additions and 2 deletions
|
@ -16,7 +16,7 @@ use nu_protocol::{
|
|||
ast::PathMember,
|
||||
engine::{EngineState, Stack, StateWorkingSet},
|
||||
format_duration, BlockId, HistoryFileFormat, PipelineData, PositionalArg, ShellError, Span,
|
||||
Type, Value, VarId,
|
||||
Spanned, Type, Value, VarId,
|
||||
};
|
||||
use reedline::{DefaultHinter, Emacs, SqliteBackedHistory, Vi};
|
||||
use std::io::{self, Write};
|
||||
|
@ -39,6 +39,7 @@ pub fn evaluate_repl(
|
|||
stack: &mut Stack,
|
||||
nushell_path: &str,
|
||||
is_perf_true: bool,
|
||||
prerun_command: Option<Spanned<String>>,
|
||||
) -> Result<()> {
|
||||
use reedline::{FileBackedHistory, Reedline, Signal};
|
||||
|
||||
|
@ -140,6 +141,17 @@ pub fn evaluate_repl(
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(s) = prerun_command {
|
||||
eval_source(
|
||||
engine_state,
|
||||
stack,
|
||||
s.item.as_bytes(),
|
||||
&format!("entry #{}", entry_num),
|
||||
PipelineData::new(Span::new(0, 0)),
|
||||
);
|
||||
engine_state.merge_env(stack, get_guaranteed_cwd(engine_state, stack))?;
|
||||
}
|
||||
|
||||
loop {
|
||||
if is_perf_true {
|
||||
info!(
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -101,7 +101,7 @@ fn main() -> Result<()> {
|
|||
} else if arg.starts_with('-') {
|
||||
// Cool, it's a flag
|
||||
let flag_value = match arg.as_ref() {
|
||||
"--commands" | "-c" | "--table-mode" | "-m" => {
|
||||
"--commands" | "-c" | "--table-mode" | "-m" | "-e" | "--execute" => {
|
||||
args.next().map(|a| escape_quote_string(&a))
|
||||
}
|
||||
"--config" | "--env-config" => args.next().map(|a| escape_quote_string(&a)),
|
||||
|
@ -341,6 +341,7 @@ fn main() -> Result<()> {
|
|||
&mut stack,
|
||||
config_files::NUSHELL_FOLDER,
|
||||
is_perf_true(),
|
||||
binary_args.execute,
|
||||
);
|
||||
if is_perf_true() {
|
||||
info!("repl eval {}:{}:{}", file!(), line!(), column!());
|
||||
|
@ -438,6 +439,7 @@ fn parse_commandline_args(
|
|||
let env_file: Option<Expression> = call.get_flag_expr("env-config");
|
||||
let log_level: Option<Expression> = call.get_flag_expr("log-level");
|
||||
let log_target: Option<Expression> = call.get_flag_expr("log-target");
|
||||
let execute: Option<Expression> = call.get_flag_expr("execute");
|
||||
let threads: Option<Value> = call.get_flag(engine_state, &mut stack, "threads")?;
|
||||
let table_mode: Option<Value> =
|
||||
call.get_flag(engine_state, &mut stack, "table-mode")?;
|
||||
|
@ -468,6 +470,7 @@ fn parse_commandline_args(
|
|||
let env_file = extract_contents(env_file)?;
|
||||
let log_level = extract_contents(log_level)?;
|
||||
let log_target = extract_contents(log_target)?;
|
||||
let execute = extract_contents(execute)?;
|
||||
|
||||
let help = call.has_flag("help");
|
||||
|
||||
|
@ -501,6 +504,7 @@ fn parse_commandline_args(
|
|||
env_file,
|
||||
log_level,
|
||||
log_target,
|
||||
execute,
|
||||
perf,
|
||||
threads,
|
||||
table_mode,
|
||||
|
@ -527,6 +531,7 @@ struct NushellCliArgs {
|
|||
env_file: Option<Spanned<String>>,
|
||||
log_level: Option<Spanned<String>>,
|
||||
log_target: Option<Spanned<String>>,
|
||||
execute: Option<Spanned<String>>,
|
||||
perf: bool,
|
||||
threads: Option<Value>,
|
||||
table_mode: Option<Value>,
|
||||
|
@ -588,6 +593,12 @@ impl Command for Nu {
|
|||
"set the target for the log to output. stdout, stderr(default), mixed or file",
|
||||
None,
|
||||
)
|
||||
.named(
|
||||
"execute",
|
||||
SyntaxShape::String,
|
||||
"run the given commands and then enter an interactive shell",
|
||||
Some('e'),
|
||||
)
|
||||
.named(
|
||||
"threads",
|
||||
SyntaxShape::Int,
|
||||
|
|
Loading…
Reference in a new issue