nushell/crates/nu-command/src/default_context.rs

192 lines
4.3 KiB
Rust
Raw Normal View History

2021-11-26 08:00:57 +00:00
use nu_protocol::engine::{EngineState, StateWorkingSet};
2021-09-02 22:58:15 +00:00
2021-10-02 02:59:11 +00:00
use crate::*;
2021-09-02 22:58:15 +00:00
2021-10-25 06:31:39 +00:00
pub fn create_default_context() -> EngineState {
let mut engine_state = EngineState::new();
2021-10-28 04:13:10 +00:00
2021-09-02 22:58:15 +00:00
let delta = {
2021-10-25 06:31:39 +00:00
let mut working_set = StateWorkingSet::new(&engine_state);
2021-09-02 22:58:15 +00:00
macro_rules! bind_command {
( $command:expr ) => {
working_set.add_decl(Box::new($command));
};
( $( $command:expr ),* ) => {
$( working_set.add_decl(Box::new($command)); )*
};
}
2021-09-23 19:03:08 +00:00
// If there are commands that have the same name as default declarations,
// they have to be registered before the main declarations. This helps to make
// them only accessible if the correct input value category is used with the
// declaration
#[cfg(feature = "dataframe")]
add_dataframe_decls(&mut working_set);
2021-10-12 17:44:23 +00:00
// TODO: sort default context items categorically
2021-10-10 20:24:54 +00:00
bind_command!(
Alias,
All,
2021-11-28 08:29:35 +00:00
Any,
Append,
2021-10-10 20:24:54 +00:00
Benchmark,
BuildString,
Cal,
2021-10-10 20:24:54 +00:00
Cd,
Clear,
Collect,
2021-10-10 20:24:54 +00:00
Cp,
2021-10-31 06:54:51 +00:00
Date,
DateFormat,
DateHumanize,
DateListTimezones,
DateNow,
DateToTable,
DateToTimezone,
Debug,
2021-10-10 20:24:54 +00:00
Def,
Describe,
2021-10-10 20:24:54 +00:00
Do,
Drop,
2021-10-10 20:24:54 +00:00
Each,
Echo,
2021-11-26 08:00:57 +00:00
Exit,
ExportCommand,
2021-10-10 20:24:54 +00:00
ExportDef,
ExportEnv,
2021-10-10 20:24:54 +00:00
External,
2021-10-31 21:53:37 +00:00
First,
2021-10-10 20:24:54 +00:00
For,
Format,
2021-10-10 20:24:54 +00:00
From,
2021-11-09 20:17:37 +00:00
FromCsv,
2021-10-10 20:24:54 +00:00
FromJson,
FromYaml,
FromYml,
2021-11-09 20:17:37 +00:00
FromTsv,
FromToml,
FromUrl,
FromEml,
FromOds,
FromIcs,
FromIni,
FromVcf,
FromSsv,
FromXml,
FromXlsx,
2021-10-10 20:24:54 +00:00
Get,
Griddle,
Help,
Hide,
If,
2021-10-11 01:57:39 +00:00
Into,
IntoBinary,
IntoDatetime,
IntoDecimal,
2021-10-11 01:57:39 +00:00
IntoFilesize,
IntoInt,
2021-11-02 19:39:16 +00:00
IntoString,
Kill,
Last,
2021-10-10 20:24:54 +00:00
Length,
Let,
LetEnv,
Lines,
Ls,
2021-10-24 23:58:18 +00:00
Math,
MathAbs,
MathAvg,
2021-11-03 11:59:08 +00:00
MathCeil,
MathFloor,
MathEval,
MathMax,
MathMedian,
MathMin,
MathMode,
MathProduct,
MathRound,
MathSqrt,
MathStddev,
MathSum,
MathVariance,
2021-10-10 20:24:54 +00:00
Mkdir,
Module,
Mv,
Nth,
2021-10-26 01:30:53 +00:00
ParEach,
2021-11-15 18:27:15 +00:00
Parse,
Prepend,
2021-10-10 20:24:54 +00:00
Ps,
Range,
Random,
Reject,
Reverse,
2021-10-10 20:24:54 +00:00
Rm,
Select,
Shuffle,
2021-10-12 21:55:29 +00:00
Size,
Skip,
SkipUntil,
SkipWhile,
Sleep,
2021-11-26 08:00:57 +00:00
Source,
2021-10-10 20:24:54 +00:00
Split,
SplitChars,
SplitColumn,
SplitRow,
Str,
StrCamelCase,
StrCapitalize,
StrCollect,
StrContains,
StrDowncase,
StrEndswith,
StrIndexOf,
StrLength,
StrFindReplace,
StrKebabCase,
StrPascalCase,
StrScreamingSnakeCase,
StrSnakeCase,
StrLpad,
StrRpad,
StrStartsWith,
StrReverse,
StrSubstring,
StrUpcase,
2021-12-02 04:38:44 +00:00
StrTrim,
2021-10-10 20:24:54 +00:00
Sys,
Table,
2021-10-29 06:26:29 +00:00
To,
ToJson,
ToUrl,
ToToml,
ToTsv,
ToCsv,
ToHtml,
ToMd,
2021-10-10 20:24:54 +00:00
Touch,
2021-12-07 08:47:48 +00:00
Uniq,
2021-10-10 20:24:54 +00:00
Use,
2021-11-13 23:02:54 +00:00
Update,
2021-10-10 20:24:54 +00:00
Where,
2021-11-04 02:32:35 +00:00
WithEnv,
2021-11-02 05:28:28 +00:00
Wrap,
Zip
2021-10-10 20:24:54 +00:00
);
2021-09-03 02:15:01 +00:00
2021-11-02 20:56:00 +00:00
#[cfg(feature = "plugin")]
bind_command!(Register);
// This is a WIP proof of concept
2021-11-26 08:00:57 +00:00
// bind_command!(ListGitBranches, Git, GitCheckout, Source);
2021-09-02 22:58:15 +00:00
working_set.render()
};
let _ = engine_state.merge_delta(delta);
2021-09-02 22:58:15 +00:00
engine_state
}