mirror of
https://github.com/nushell/nushell.git
synced 2025-08-15 00:42:30 +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:
@ -1,5 +1,4 @@
|
||||
use crate::ast::Call;
|
||||
use crate::Span;
|
||||
use crate::{ast::Call, Span};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UnevaluatedCallInfo {
|
||||
|
@ -1,27 +1,24 @@
|
||||
use crate::{
|
||||
ast::Block,
|
||||
debugger::{Debugger, NoopDebugger},
|
||||
engine::{
|
||||
usage::{build_usage, Usage},
|
||||
CachedFile, Command, CommandType, EnvVars, OverlayFrame, ScopeFrame, Stack, StateDelta,
|
||||
Variable, Visibility, DEFAULT_OVERLAY_NAME,
|
||||
},
|
||||
BlockId, Category, Config, DeclId, Example, FileId, HistoryConfig, Module, ModuleId, OverlayId,
|
||||
ShellError, Signature, Span, Type, Value, VarId, VirtualPathId,
|
||||
};
|
||||
use fancy_regex::Regex;
|
||||
use lru::LruCache;
|
||||
|
||||
use super::cached_file::CachedFile;
|
||||
use super::{usage::build_usage, usage::Usage, StateDelta};
|
||||
use super::{
|
||||
Command, CommandType, EnvVars, OverlayFrame, ScopeFrame, Stack, Variable, Visibility,
|
||||
DEFAULT_OVERLAY_NAME,
|
||||
};
|
||||
use crate::ast::Block;
|
||||
use crate::debugger::{Debugger, NoopDebugger};
|
||||
use crate::{
|
||||
BlockId, Config, DeclId, Example, FileId, HistoryConfig, Module, ModuleId, OverlayId,
|
||||
ShellError, Signature, Span, Type, VarId, VirtualPathId,
|
||||
};
|
||||
use crate::{Category, Value};
|
||||
use std::collections::HashMap;
|
||||
use std::num::NonZeroUsize;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, AtomicU32},
|
||||
Arc, Mutex, MutexGuard, PoisonError,
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
num::NonZeroUsize,
|
||||
path::{Path, PathBuf},
|
||||
sync::{
|
||||
atomic::{AtomicBool, AtomicU32, Ordering},
|
||||
Arc, Mutex, MutexGuard, PoisonError,
|
||||
},
|
||||
};
|
||||
|
||||
type PoisonDebuggerError<'a> = PoisonError<MutexGuard<'a, Box<dyn Debugger>>>;
|
||||
|
@ -1,12 +1,14 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
engine::{EngineState, DEFAULT_OVERLAY_NAME},
|
||||
engine::{
|
||||
EngineState, Redirection, StackCallArgGuard, StackCaptureGuard, StackIoGuard, StackStdio,
|
||||
DEFAULT_OVERLAY_NAME,
|
||||
},
|
||||
IoStream, ShellError, Span, Value, VarId, ENV_VARIABLE_ID, NU_VARIABLE_ID,
|
||||
};
|
||||
|
||||
use super::{Redirection, StackCallArgGuard, StackCaptureGuard, StackIoGuard, StackStdio};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
/// Environment variables per overlay
|
||||
pub type EnvVars = HashMap<String, HashMap<String, Value>>;
|
||||
|
@ -1,8 +1,11 @@
|
||||
use super::cached_file::CachedFile;
|
||||
use super::{usage::Usage, Command, EngineState, OverlayFrame, ScopeFrame, Variable, VirtualPath};
|
||||
use crate::ast::Block;
|
||||
use crate::Module;
|
||||
|
||||
use crate::{
|
||||
ast::Block,
|
||||
engine::{
|
||||
usage::Usage, CachedFile, Command, EngineState, OverlayFrame, ScopeFrame, Variable,
|
||||
VirtualPath,
|
||||
},
|
||||
Module,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "plugin")]
|
||||
|
@ -1,17 +1,18 @@
|
||||
use super::cached_file::CachedFile;
|
||||
use super::CommandType;
|
||||
use super::{
|
||||
usage::build_usage, Command, EngineState, OverlayFrame, StateDelta, Variable, VirtualPath,
|
||||
Visibility, PWD_ENV,
|
||||
use crate::{
|
||||
ast::Block,
|
||||
engine::{
|
||||
usage::build_usage, CachedFile, Command, CommandType, EngineState, OverlayFrame,
|
||||
StateDelta, Variable, VirtualPath, Visibility, PWD_ENV,
|
||||
},
|
||||
BlockId, Category, Config, DeclId, FileId, Module, ModuleId, ParseError, ParseWarning, Span,
|
||||
Type, Value, VarId, VirtualPathId,
|
||||
};
|
||||
use crate::ast::Block;
|
||||
use crate::{BlockId, Config, DeclId, FileId, Module, ModuleId, Span, Type, VarId, VirtualPathId};
|
||||
use crate::{Category, ParseError, ParseWarning, Value};
|
||||
use core::panic;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
#[cfg(feature = "plugin")]
|
||||
use crate::{PluginIdentity, RegisteredPlugin};
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::{engine::Stack, IoStream};
|
||||
use std::{
|
||||
fs::File,
|
||||
mem,
|
||||
@ -5,10 +6,6 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use crate::IoStream;
|
||||
|
||||
use super::Stack;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Redirection {
|
||||
/// A pipe redirection.
|
||||
|
Reference in New Issue
Block a user