mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 10:23:52 +01:00
586c6d9fa8
* Port str find_replace command * Add regex crate as dependency Co-authored-by: Stefan Stanciulescu <contact@stefanstanciulescu.com>
140 lines
3.0 KiB
Rust
140 lines
3.0 KiB
Rust
use nu_protocol::{
|
|
engine::{EngineState, StateWorkingSet},
|
|
Signature,
|
|
};
|
|
|
|
use crate::*;
|
|
|
|
pub fn create_default_context() -> EngineState {
|
|
let mut engine_state = EngineState::new();
|
|
|
|
let delta = {
|
|
let mut working_set = StateWorkingSet::new(&engine_state);
|
|
|
|
macro_rules! bind_command {
|
|
( $command:expr ) => {
|
|
working_set.add_decl(Box::new($command));
|
|
};
|
|
( $( $command:expr ),* ) => {
|
|
$( working_set.add_decl(Box::new($command)); )*
|
|
};
|
|
}
|
|
|
|
// TODO: sort default context items categorically
|
|
bind_command!(
|
|
Alias,
|
|
Benchmark,
|
|
BuildString,
|
|
Cd,
|
|
Collect,
|
|
Cp,
|
|
Date,
|
|
DateFormat,
|
|
DateHumanize,
|
|
DateListTimezones,
|
|
DateNow,
|
|
DateToTable,
|
|
DateToTimezone,
|
|
Def,
|
|
Do,
|
|
Each,
|
|
Echo,
|
|
ExportDef,
|
|
External,
|
|
First,
|
|
For,
|
|
Format,
|
|
From,
|
|
FromCsv,
|
|
FromJson,
|
|
FromYaml,
|
|
FromYml,
|
|
FromTsv,
|
|
Get,
|
|
Griddle,
|
|
Help,
|
|
Hide,
|
|
If,
|
|
Into,
|
|
IntoBinary,
|
|
IntoFilesize,
|
|
IntoInt,
|
|
IntoString,
|
|
Last,
|
|
Length,
|
|
Let,
|
|
LetEnv,
|
|
Lines,
|
|
Ls,
|
|
Math,
|
|
MathAbs,
|
|
MathAvg,
|
|
MathCeil,
|
|
MathFloor,
|
|
MathEval,
|
|
MathMax,
|
|
MathMedian,
|
|
MathMin,
|
|
MathMode,
|
|
MathProduct,
|
|
MathRound,
|
|
MathSqrt,
|
|
MathStddev,
|
|
MathSum,
|
|
MathVariance,
|
|
Mkdir,
|
|
Module,
|
|
Mv,
|
|
ParEach,
|
|
Ps,
|
|
Range,
|
|
Reverse,
|
|
Rm,
|
|
Select,
|
|
Shuffle,
|
|
Size,
|
|
Split,
|
|
SplitChars,
|
|
SplitColumn,
|
|
SplitRow,
|
|
Str,
|
|
StrCamelCase,
|
|
StrCapitalize,
|
|
StrCollect,
|
|
StrContains,
|
|
StrDowncase,
|
|
StrEndswith,
|
|
StrFindReplace,
|
|
StrKebabCase,
|
|
StrPascalCase,
|
|
StrScreamingSnakeCase,
|
|
StrSnakeCase,
|
|
Sys,
|
|
Table,
|
|
To,
|
|
ToJson,
|
|
Touch,
|
|
Use,
|
|
Where,
|
|
WithEnv,
|
|
Wrap,
|
|
Zip
|
|
);
|
|
|
|
#[cfg(feature = "plugin")]
|
|
bind_command!(Register);
|
|
|
|
// This is a WIP proof of concept
|
|
bind_command!(ListGitBranches, Git, GitCheckout, Source);
|
|
|
|
let sig = Signature::build("exit");
|
|
working_set.add_decl(sig.predeclare());
|
|
|
|
working_set.render()
|
|
};
|
|
|
|
engine_state.merge_delta(delta);
|
|
|
|
engine_state
|
|
}
|