mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 18:15:04 +02:00
Add command_prelude
module (#12291)
# Description When implementing a `Command`, one must also import all the types present in the function signatures for `Command`. This makes it so that we often import the same set of types in each command implementation file. E.g., something like this: ```rust use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ record, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value, }; ``` This PR adds the `nu_engine::command_prelude` module which contains the necessary and commonly used types to implement a `Command`: ```rust // command_prelude.rs pub use crate::CallExt; pub use nu_protocol::{ ast::{Call, CellPath}, engine::{Command, EngineState, Stack}, record, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, IntoSpanned, PipelineData, Record, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, }; ``` This should reduce the boilerplate needed to implement a command and also gives us a place to track the breadth of the `Command` API. I tried to be conservative with what went into the prelude modules, since it might be hard/annoying to remove items from the prelude in the future. Let me know if something should be included or excluded.
This commit is contained in:
7
crates/nu-command/src/env/config/config_.rs
vendored
7
crates/nu-command/src/env/config/config_.rs
vendored
@ -1,9 +1,4 @@
|
||||
use nu_engine::get_full_help;
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value,
|
||||
};
|
||||
use nu_engine::{command_prelude::*, get_full_help};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ConfigMeta;
|
||||
|
@ -1,12 +1,6 @@
|
||||
use nu_engine::{env_to_strings, CallExt};
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value,
|
||||
};
|
||||
|
||||
use super::utils::gen_command;
|
||||
use nu_cmd_base::util::get_editor;
|
||||
use nu_engine::{command_prelude::*, env_to_strings};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ConfigEnv;
|
||||
|
@ -1,12 +1,6 @@
|
||||
use nu_engine::{env_to_strings, CallExt};
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value,
|
||||
};
|
||||
|
||||
use super::utils::gen_command;
|
||||
use nu_cmd_base::util::get_editor;
|
||||
use nu_engine::{command_prelude::*, env_to_strings};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ConfigNu;
|
||||
|
@ -1,10 +1,6 @@
|
||||
use chrono::Local;
|
||||
use nu_engine::CallExt;
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, Example, PipelineData, ShellError, Signature, Type,
|
||||
};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
use nu_utils::{get_default_config, get_default_env};
|
||||
use std::io::Write;
|
||||
|
||||
|
7
crates/nu-command/src/env/config/utils.rs
vendored
7
crates/nu-command/src/env/config/utils.rs
vendored
@ -1,9 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use nu_protocol::{IoStream, Span, Spanned};
|
||||
|
||||
use crate::ExternalCommand;
|
||||
use nu_protocol::{IoStream, Span, Spanned};
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
pub(crate) fn gen_command(
|
||||
span: Span,
|
||||
|
9
crates/nu-command/src/env/export_env.rs
vendored
9
crates/nu-command/src/env/export_env.rs
vendored
@ -1,10 +1,5 @@
|
||||
use nu_engine::{get_eval_block, redirect_env, CallExt};
|
||||
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Closure, Command, EngineState, Stack},
|
||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
|
||||
};
|
||||
use nu_engine::{command_prelude::*, get_eval_block, redirect_env};
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ExportEnv;
|
||||
|
7
crates/nu-command/src/env/load_env.rs
vendored
7
crates/nu-command/src/env/load_env.rs
vendored
@ -1,9 +1,4 @@
|
||||
use nu_engine::{current_dir, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, Record, ShellError, Signature, SyntaxShape, Type, Value,
|
||||
};
|
||||
use nu_engine::{command_prelude::*, current_dir};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LoadEnv;
|
||||
|
13
crates/nu-command/src/env/source_env.rs
vendored
13
crates/nu-command/src/env/source_env.rs
vendored
@ -1,15 +1,8 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use nu_engine::{
|
||||
find_in_dirs_env, get_dirs_var_from_call, get_eval_block_with_early_return, redirect_env,
|
||||
CallExt,
|
||||
};
|
||||
use nu_protocol::ast::Call;
|
||||
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, Value,
|
||||
command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block_with_early_return,
|
||||
redirect_env,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Source a file for environment variables.
|
||||
#[derive(Clone)]
|
||||
|
10
crates/nu-command/src/env/with_env.rs
vendored
10
crates/nu-command/src/env/with_env.rs
vendored
@ -1,13 +1,7 @@
|
||||
use nu_engine::{command_prelude::*, eval_block};
|
||||
use nu_protocol::{debugger::WithoutDebug, engine::Closure};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use nu_engine::{eval_block, CallExt};
|
||||
use nu_protocol::debugger::WithoutDebug;
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Closure, Command, EngineState, Stack},
|
||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct WithEnv;
|
||||
|
||||
|
Reference in New Issue
Block a user