mirror of
https://github.com/nushell/nushell.git
synced 2025-08-11 17:34: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:
@ -1,10 +1,10 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::NuGlob;
|
||||
use crate::ast::{CellPath, PathMember};
|
||||
use crate::engine::{Block, Closure};
|
||||
use crate::{Range, Record, ShellError, Spanned, Value};
|
||||
use crate::{
|
||||
ast::{CellPath, PathMember},
|
||||
engine::{Block, Closure},
|
||||
NuGlob, Range, Record, ShellError, Spanned, Value,
|
||||
};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub trait FromValue: Sized {
|
||||
fn from_value(v: Value) -> Result<Self, ShellError>;
|
||||
|
@ -17,23 +17,26 @@ pub use lazy_record::LazyRecord;
|
||||
pub use range::*;
|
||||
pub use record::Record;
|
||||
|
||||
use crate::ast::{Bits, Boolean, CellPath, Comparison, Math, Operator, PathMember, RangeInclusion};
|
||||
use crate::engine::{Closure, EngineState};
|
||||
use crate::{did_you_mean, BlockId, Config, ShellError, Span, Type};
|
||||
|
||||
use crate::{
|
||||
ast::{Bits, Boolean, CellPath, Comparison, Math, Operator, PathMember, RangeInclusion},
|
||||
did_you_mean,
|
||||
engine::{Closure, EngineState},
|
||||
BlockId, Config, ShellError, Span, Type,
|
||||
};
|
||||
use chrono::{DateTime, Datelike, FixedOffset, Locale, TimeZone};
|
||||
use chrono_humanize::HumanTime;
|
||||
use fancy_regex::Regex;
|
||||
use nu_utils::locale::LOCALE_OVERRIDE_ENV_VAR;
|
||||
use nu_utils::{contains_emoji, locale::get_system_locale_string, IgnoreCaseExt};
|
||||
use nu_utils::{
|
||||
contains_emoji,
|
||||
locale::{get_system_locale_string, LOCALE_OVERRIDE_ENV_VAR},
|
||||
IgnoreCaseExt,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Write;
|
||||
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
fmt::Display,
|
||||
cmp::Ordering,
|
||||
fmt::{Debug, Display, Write},
|
||||
path::PathBuf,
|
||||
{cmp::Ordering, fmt::Debug},
|
||||
};
|
||||
|
||||
/// Core structured values that pass through the pipeline in Nushell.
|
||||
|
Reference in New Issue
Block a user