mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 17:54:22 +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,13 +1,7 @@
|
||||
use std::path::Path;
|
||||
|
||||
use super::PathSubcommandArguments;
|
||||
use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
||||
use nu_protocol::{
|
||||
engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Spanned,
|
||||
SyntaxShape, Type, Value,
|
||||
};
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
use std::path::Path;
|
||||
|
||||
struct Arguments {
|
||||
replace: Option<Spanned<String>>,
|
||||
|
@ -1,14 +1,7 @@
|
||||
use std::path::Path;
|
||||
|
||||
use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
||||
use nu_protocol::{
|
||||
engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Spanned,
|
||||
SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
use super::PathSubcommandArguments;
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
use std::path::Path;
|
||||
|
||||
struct Arguments {
|
||||
replace: Option<Spanned<String>>,
|
||||
|
@ -1,14 +1,8 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use nu_engine::{current_dir, current_dir_const, CallExt};
|
||||
use nu_path::expand_path_with;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
||||
use nu_protocol::{
|
||||
engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
use super::PathSubcommandArguments;
|
||||
use nu_engine::{command_prelude::*, current_dir, current_dir_const};
|
||||
use nu_path::expand_path_with;
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
struct Arguments {
|
||||
pwd: PathBuf,
|
||||
|
@ -1,15 +1,11 @@
|
||||
use std::path::Path;
|
||||
|
||||
use nu_engine::env::{current_dir_str, current_dir_str_const};
|
||||
use nu_engine::CallExt;
|
||||
use nu_path::{canonicalize_with, expand_path_with};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
||||
use nu_protocol::{
|
||||
engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
use super::PathSubcommandArguments;
|
||||
use nu_engine::{
|
||||
command_prelude::*,
|
||||
env::{current_dir_str, current_dir_str_const},
|
||||
};
|
||||
use nu_path::{canonicalize_with, expand_path_with};
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
use std::path::Path;
|
||||
|
||||
struct Arguments {
|
||||
strict: bool,
|
||||
|
@ -1,14 +1,7 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
||||
use nu_protocol::{
|
||||
engine::Command, Category, Example, PipelineData, Record, ShellError, Signature, Span, Spanned,
|
||||
SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
use super::PathSubcommandArguments;
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
struct Arguments {
|
||||
append: Vec<Spanned<String>>,
|
||||
|
@ -9,8 +9,6 @@ mod relative_to;
|
||||
mod split;
|
||||
mod r#type;
|
||||
|
||||
use std::path::Path as StdPath;
|
||||
|
||||
pub use basename::SubCommand as PathBasename;
|
||||
pub use dirname::SubCommand as PathDirname;
|
||||
pub use exists::SubCommand as PathExists;
|
||||
@ -23,6 +21,7 @@ pub use relative_to::SubCommand as PathRelativeTo;
|
||||
pub use split::SubCommand as PathSplit;
|
||||
|
||||
use nu_protocol::{ShellError, Span, Value};
|
||||
use std::path::Path as StdPath;
|
||||
|
||||
#[cfg(windows)]
|
||||
const ALLOWED_COLUMNS: [&str; 4] = ["prefix", "parent", "stem", "extension"];
|
||||
|
@ -1,14 +1,7 @@
|
||||
use std::path::Path;
|
||||
|
||||
use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
||||
use nu_protocol::{
|
||||
engine::Command, Category, Example, PipelineData, Record, ShellError, Signature, Span, Spanned,
|
||||
SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
use super::PathSubcommandArguments;
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
use std::path::Path;
|
||||
|
||||
struct Arguments {
|
||||
extension: Option<Spanned<String>>,
|
||||
@ -97,8 +90,6 @@ On Windows, an extra 'prefix' column is added."#
|
||||
|
||||
#[cfg(windows)]
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
use nu_protocol::record;
|
||||
|
||||
vec![
|
||||
Example {
|
||||
description: "Parse a single path",
|
||||
@ -148,8 +139,6 @@ On Windows, an extra 'prefix' column is added."#
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
use nu_protocol::record;
|
||||
|
||||
vec![
|
||||
Example {
|
||||
description: "Parse a path",
|
||||
|
@ -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 PathCommand;
|
||||
|
@ -1,15 +1,8 @@
|
||||
use std::path::Path;
|
||||
|
||||
use nu_engine::CallExt;
|
||||
use nu_path::expand_to_real_path;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
||||
use nu_protocol::{
|
||||
engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Spanned,
|
||||
SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
use super::PathSubcommandArguments;
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_path::expand_to_real_path;
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
use std::path::Path;
|
||||
|
||||
struct Arguments {
|
||||
path: Spanned<String>,
|
||||
|
@ -1,12 +1,7 @@
|
||||
use std::path::{Component, Path};
|
||||
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
||||
use nu_protocol::{
|
||||
engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
use super::PathSubcommandArguments;
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
use std::path::{Component, Path};
|
||||
|
||||
struct Arguments;
|
||||
|
||||
|
@ -1,13 +1,8 @@
|
||||
use std::path::Path;
|
||||
|
||||
use nu_path::expand_tilde;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
||||
use nu_protocol::{
|
||||
engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
use super::PathSubcommandArguments;
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_path::expand_tilde;
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
use std::path::Path;
|
||||
|
||||
struct Arguments;
|
||||
|
||||
|
Reference in New Issue
Block a user