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

308 lines
6.1 KiB
Rust
Raw Normal View History

2021-11-26 09:00:57 +01:00
use nu_protocol::engine::{EngineState, StateWorkingSet};
2021-09-03 00:58:15 +02:00
2021-10-02 04:59:11 +02:00
use crate::*;
2021-09-03 00:58:15 +02:00
2021-10-25 08:31:39 +02:00
pub fn create_default_context() -> EngineState {
let mut engine_state = EngineState::new();
2021-10-28 06:13:10 +02:00
2021-09-03 00:58:15 +02:00
let delta = {
2021-10-25 08:31:39 +02:00
let mut working_set = StateWorkingSet::new(&engine_state);
2021-09-03 00:58:15 +02:00
macro_rules! bind_command {
( $( $command:expr ),* $(,)? ) => {
$( working_set.add_decl(Box::new($command)); )*
};
}
2021-09-23 21:03:08 +02: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);
// Core
bind_command! {
2021-10-10 22:24:54 +02:00
Alias,
Debug,
2021-10-10 22:24:54 +02:00
Def,
Describe,
2021-10-10 22:24:54 +02:00
Do,
Echo,
ExportCommand,
2021-10-10 22:24:54 +02:00
ExportDef,
ExportEnv,
2021-10-10 22:24:54 +02:00
For,
Help,
Hide,
2021-12-22 12:19:38 +01:00
History,
2021-10-10 22:24:54 +02:00
If,
Let,
Metadata,
Module,
Source,
Use,
Version,
};
// Filters
bind_command! {
All,
Any,
Append,
Collect,
Columns,
Compact,
Drop,
DropColumn,
2021-12-15 13:26:15 +01:00
DropNth,
Each,
Empty,
First,
Flatten,
Get,
Keep,
KeepUntil,
KeepWhile,
Last,
2021-10-10 22:24:54 +02:00
Length,
Lines,
Nth,
2021-10-26 03:30:53 +02:00
ParEach,
Prepend,
Range,
Reject,
Reverse,
2021-10-10 22:24:54 +02:00
Select,
Shuffle,
Skip,
SkipUntil,
SkipWhile,
Uniq,
Update,
Where,
Wrap,
Zip,
};
// Path
bind_command! {
Path,
PathBasename,
PathDirname,
PathExists,
PathExpand,
PathJoin,
PathParse,
PathRelativeTo,
PathSplit,
PathType,
};
// System
bind_command! {
Benchmark,
External,
Ps,
Sys,
};
// Strings
bind_command! {
BuildString,
Char,
Decode,
Format,
Parse,
Size,
2021-10-10 22:24:54 +02:00
Split,
SplitChars,
SplitColumn,
SplitRow,
Str,
StrCamelCase,
StrCapitalize,
StrCollect,
StrContains,
StrDowncase,
StrEndswith,
StrFindReplace,
StrIndexOf,
StrKebabCase,
StrLength,
StrLpad,
StrPascalCase,
StrReverse,
StrRpad,
StrScreamingSnakeCase,
StrSnakeCase,
StrStartsWith,
StrSubstring,
2021-12-02 05:38:44 +01:00
StrTrim,
StrUpcase
};
// FileSystem
bind_command! {
Cd,
Cp,
Ls,
Mkdir,
Mv,
2021-12-24 20:24:55 +01:00
Open,
Rm,
Touch,
};
// Platform
bind_command! {
Ansi,
AnsiGradient,
AnsiStrip,
Clear,
Kill,
Sleep,
};
// Date
bind_command! {
Date,
DateFormat,
DateHumanize,
DateListTimezones,
DateNow,
DateToTable,
DateToTimezone,
};
// Shells
bind_command! {
Exit,
};
// Formats
bind_command! {
From,
FromCsv,
FromEml,
FromIcs,
FromIni,
FromJson,
FromOds,
FromSsv,
FromToml,
FromTsv,
FromUrl,
FromVcf,
FromXlsx,
FromXml,
FromYaml,
FromYml,
2021-10-29 08:26:29 +02:00
To,
ToCsv,
ToHtml,
ToJson,
ToMd,
ToToml,
ToTsv,
ToCsv,
Touch,
Use,
Update,
Where,
ToUrl,
2021-12-10 21:46:43 +01:00
ToXml,
ToYaml,
};
// Viewers
bind_command! {
Griddle,
Table,
};
// Conversions
bind_command! {
Into,
IntoBool,
IntoBinary,
IntoDatetime,
IntoDecimal,
IntoFilesize,
IntoInt,
IntoString,
};
// Env
bind_command! {
LetEnv,
2021-11-04 03:32:35 +01:00
WithEnv,
Env,
};
// Math
bind_command! {
Math,
MathAbs,
MathAvg,
MathCeil,
MathEval,
MathFloor,
MathMax,
MathMedian,
MathMin,
MathMode,
MathProduct,
MathRound,
MathSqrt,
MathStddev,
MathSum,
MathVariance,
};
// Network
bind_command! {
Url,
UrlHost,
UrlPath,
UrlQuery,
UrlScheme,
}
// Random
bind_command! {
Random,
RandomBool,
RandomChars,
RandomDecimal,
RandomDice,
RandomInteger,
RandomUuid,
};
// Generators
bind_command! {
Cal,
};
// Hash
bind_command! {
Hash,
HashMd5::default(),
HashSha256::default(),
};
2021-09-03 04:15:01 +02:00
2021-11-02 21:56:00 +01:00
#[cfg(feature = "plugin")]
bind_command!(Register);
// This is a WIP proof of concept
2021-11-26 09:00:57 +01:00
// bind_command!(ListGitBranches, Git, GitCheckout, Source);
2021-09-03 00:58:15 +02:00
working_set.render()
};
let _ = engine_state.merge_delta(delta);
2021-09-03 00:58:15 +02:00
engine_state
}