2021-11-26 09:00:57 +01:00
|
|
|
use nu_protocol::engine::{EngineState, StateWorkingSet};
|
2021-09-03 00:58:15 +02:00
|
|
|
|
2022-01-04 23:30:34 +01:00
|
|
|
use std::path::Path;
|
|
|
|
|
2021-10-02 04:59:11 +02:00
|
|
|
use crate::*;
|
2021-09-03 00:58:15 +02:00
|
|
|
|
2022-01-04 23:30:34 +01:00
|
|
|
pub fn create_default_context(cwd: impl AsRef<Path>) -> EngineState {
|
2021-10-25 08:31:39 +02:00
|
|
|
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
|
|
|
|
2021-10-10 06:13:15 +02:00
|
|
|
macro_rules! bind_command {
|
2021-12-11 00:14:28 +01:00
|
|
|
( $( $command:expr ),* $(,)? ) => {
|
2021-10-10 06:13:15 +02:00
|
|
|
$( working_set.add_decl(Box::new($command)); )*
|
|
|
|
};
|
|
|
|
}
|
2021-09-23 21:03:08 +02:00
|
|
|
|
2021-11-28 20:35:02 +01: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")]
|
2021-12-06 05:09:49 +01:00
|
|
|
add_dataframe_decls(&mut working_set);
|
2021-11-28 20:35:02 +01:00
|
|
|
|
2021-12-11 04:07:39 +01:00
|
|
|
// Core
|
|
|
|
bind_command! {
|
2021-10-10 22:24:54 +02:00
|
|
|
Alias,
|
2021-11-19 06:00:29 +01:00
|
|
|
Debug,
|
2021-10-10 22:24:54 +02:00
|
|
|
Def,
|
2021-11-19 06:00:29 +01:00
|
|
|
Describe,
|
2021-10-10 22:24:54 +02:00
|
|
|
Do,
|
2021-11-01 09:12:48 +01:00
|
|
|
Echo,
|
2021-11-16 00:16:06 +01:00
|
|
|
ExportCommand,
|
2021-10-10 22:24:54 +02:00
|
|
|
ExportDef,
|
2021-11-16 00:16:06 +01:00
|
|
|
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,
|
2021-12-30 05:54:33 +01:00
|
|
|
Ignore,
|
2021-12-11 04:07:39 +01:00
|
|
|
Let,
|
2021-12-24 01:16:50 +01:00
|
|
|
Metadata,
|
2021-12-11 04:07:39 +01:00
|
|
|
Module,
|
|
|
|
Source,
|
2022-01-24 16:05:19 +01:00
|
|
|
Tutor,
|
2021-12-11 04:07:39 +01:00
|
|
|
Use,
|
2021-12-11 21:08:17 +01:00
|
|
|
Version,
|
2021-12-11 04:07:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Filters
|
|
|
|
bind_command! {
|
|
|
|
All,
|
|
|
|
Any,
|
|
|
|
Append,
|
|
|
|
Collect,
|
2021-12-18 19:14:28 +01:00
|
|
|
Columns,
|
2021-12-23 04:08:39 +01:00
|
|
|
Compact,
|
2022-01-25 16:02:15 +01:00
|
|
|
Default,
|
2021-12-11 04:07:39 +01:00
|
|
|
Drop,
|
2021-12-14 20:54:27 +01:00
|
|
|
DropColumn,
|
2021-12-15 13:26:15 +01:00
|
|
|
DropNth,
|
2021-12-11 04:07:39 +01:00
|
|
|
Each,
|
2021-12-19 20:11:57 +01:00
|
|
|
Empty,
|
2021-12-31 00:41:18 +01:00
|
|
|
Every,
|
2022-01-23 23:32:02 +01:00
|
|
|
Find,
|
2021-12-11 04:07:39 +01:00
|
|
|
First,
|
2021-12-17 21:44:51 +01:00
|
|
|
Flatten,
|
2021-12-11 04:07:39 +01:00
|
|
|
Get,
|
2022-01-21 21:28:21 +01:00
|
|
|
GroupBy,
|
2021-12-17 01:57:02 +01:00
|
|
|
Keep,
|
2022-01-22 00:50:26 +01:00
|
|
|
Merge,
|
2022-01-24 20:43:38 +01:00
|
|
|
Move,
|
2021-12-17 01:57:02 +01:00
|
|
|
KeepUntil,
|
|
|
|
KeepWhile,
|
2021-10-26 20:29:00 +02:00
|
|
|
Last,
|
2021-10-10 22:24:54 +02:00
|
|
|
Length,
|
|
|
|
Lines,
|
2021-12-10 01:16:04 +01:00
|
|
|
Nth,
|
2021-10-26 03:30:53 +02:00
|
|
|
ParEach,
|
2021-12-07 09:46:21 +01:00
|
|
|
Prepend,
|
2021-10-30 19:51:20 +02:00
|
|
|
Range,
|
2022-01-08 01:40:40 +01:00
|
|
|
Reduce,
|
2021-12-05 04:09:45 +01:00
|
|
|
Reject,
|
2021-11-07 19:18:27 +01:00
|
|
|
Reverse,
|
2021-10-10 22:24:54 +02:00
|
|
|
Select,
|
2021-11-07 02:19:57 +01:00
|
|
|
Shuffle,
|
2021-11-29 07:52:23 +01:00
|
|
|
Skip,
|
|
|
|
SkipUntil,
|
|
|
|
SkipWhile,
|
2022-01-22 21:49:50 +01:00
|
|
|
SortBy,
|
2022-01-21 21:28:21 +01:00
|
|
|
Transpose,
|
2021-12-11 04:07:39 +01:00
|
|
|
Uniq,
|
|
|
|
Update,
|
|
|
|
Where,
|
|
|
|
Wrap,
|
|
|
|
Zip,
|
|
|
|
};
|
|
|
|
|
2021-12-13 02:47:14 +01:00
|
|
|
// Path
|
|
|
|
bind_command! {
|
|
|
|
Path,
|
|
|
|
PathBasename,
|
|
|
|
PathDirname,
|
|
|
|
PathExists,
|
|
|
|
PathExpand,
|
|
|
|
PathJoin,
|
|
|
|
PathParse,
|
|
|
|
PathRelativeTo,
|
|
|
|
PathSplit,
|
|
|
|
PathType,
|
|
|
|
};
|
|
|
|
|
2021-12-11 04:07:39 +01:00
|
|
|
// System
|
|
|
|
bind_command! {
|
|
|
|
Benchmark,
|
2022-01-25 18:27:35 +01:00
|
|
|
Exec,
|
2021-12-11 04:07:39 +01:00
|
|
|
External,
|
|
|
|
Ps,
|
|
|
|
Sys,
|
|
|
|
};
|
|
|
|
|
2022-01-20 19:02:53 +01:00
|
|
|
#[cfg(feature = "which")]
|
|
|
|
bind_command! { Which };
|
|
|
|
|
2021-12-11 04:07:39 +01:00
|
|
|
// Strings
|
|
|
|
bind_command! {
|
|
|
|
BuildString,
|
2021-12-16 00:08:12 +01:00
|
|
|
Char,
|
2021-12-24 08:22:11 +01:00
|
|
|
Decode,
|
2021-12-11 04:07:39 +01:00
|
|
|
Format,
|
|
|
|
Parse,
|
|
|
|
Size,
|
2021-10-10 22:24:54 +02:00
|
|
|
Split,
|
|
|
|
SplitChars,
|
|
|
|
SplitColumn,
|
|
|
|
SplitRow,
|
2021-11-09 02:59:44 +01:00
|
|
|
Str,
|
|
|
|
StrCamelCase,
|
2021-11-09 08:40:56 +01:00
|
|
|
StrCapitalize,
|
2021-11-09 02:59:44 +01:00
|
|
|
StrCollect,
|
2021-11-09 21:16:53 +01:00
|
|
|
StrContains,
|
|
|
|
StrDowncase,
|
2021-11-10 01:51:55 +01:00
|
|
|
StrEndswith,
|
2021-11-11 00:11:34 +01:00
|
|
|
StrFindReplace,
|
2021-12-11 04:07:39 +01:00
|
|
|
StrIndexOf,
|
2021-11-09 02:59:44 +01:00
|
|
|
StrKebabCase,
|
2021-12-11 04:07:39 +01:00
|
|
|
StrLength,
|
|
|
|
StrLpad,
|
2021-11-09 02:59:44 +01:00
|
|
|
StrPascalCase,
|
2021-12-11 04:07:39 +01:00
|
|
|
StrReverse,
|
|
|
|
StrRpad,
|
2021-11-09 02:59:44 +01:00
|
|
|
StrScreamingSnakeCase,
|
|
|
|
StrSnakeCase,
|
2021-11-16 00:16:56 +01:00
|
|
|
StrStartsWith,
|
2021-12-01 07:42:57 +01:00
|
|
|
StrSubstring,
|
2021-12-02 05:38:44 +01:00
|
|
|
StrTrim,
|
2021-12-17 18:40:47 +01:00
|
|
|
StrUpcase
|
2021-12-11 04:07:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// FileSystem
|
|
|
|
bind_command! {
|
|
|
|
Cd,
|
|
|
|
Cp,
|
|
|
|
Ls,
|
|
|
|
Mkdir,
|
|
|
|
Mv,
|
2021-12-24 20:24:55 +01:00
|
|
|
Open,
|
2021-12-11 04:07:39 +01:00
|
|
|
Rm,
|
2022-01-15 21:44:20 +01:00
|
|
|
Save,
|
2021-12-11 04:07:39 +01:00
|
|
|
Touch,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Platform
|
|
|
|
bind_command! {
|
2021-12-17 18:40:47 +01:00
|
|
|
Ansi,
|
|
|
|
AnsiGradient,
|
2021-12-17 21:32:03 +01:00
|
|
|
AnsiStrip,
|
2021-12-11 04:07:39 +01:00
|
|
|
Clear,
|
2022-01-16 05:28:28 +01:00
|
|
|
Input,
|
2022-01-23 23:09:39 +01:00
|
|
|
InputKeys,
|
2021-12-11 04:07:39 +01:00
|
|
|
Kill,
|
|
|
|
Sleep,
|
2022-01-21 04:31:33 +01:00
|
|
|
TermSize,
|
2021-12-11 04:07:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Date
|
|
|
|
bind_command! {
|
|
|
|
Date,
|
|
|
|
DateFormat,
|
|
|
|
DateHumanize,
|
|
|
|
DateListTimezones,
|
|
|
|
DateNow,
|
|
|
|
DateToTable,
|
|
|
|
DateToTimezone,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Shells
|
|
|
|
bind_command! {
|
2022-01-05 05:35:50 +01:00
|
|
|
Enter,
|
2021-12-11 04:07:39 +01:00
|
|
|
Exit,
|
2022-01-05 05:35:50 +01:00
|
|
|
GotoShell,
|
|
|
|
NextShell,
|
|
|
|
PrevShell,
|
|
|
|
Shells,
|
2021-12-11 04:07:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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,
|
2021-12-03 03:02:22 +01:00
|
|
|
ToCsv,
|
2021-12-10 02:16:35 +01:00
|
|
|
ToHtml,
|
2021-12-11 04:07:39 +01:00
|
|
|
ToJson,
|
2021-12-10 02:16:35 +01:00
|
|
|
ToMd,
|
2021-12-11 04:07:39 +01:00
|
|
|
ToToml,
|
|
|
|
ToTsv,
|
2021-12-11 21:08:17 +01:00
|
|
|
ToCsv,
|
|
|
|
Touch,
|
|
|
|
Use,
|
|
|
|
Update,
|
|
|
|
Where,
|
2021-12-11 04:07:39 +01:00
|
|
|
ToUrl,
|
2021-12-10 21:46:43 +01:00
|
|
|
ToXml,
|
2021-12-11 04:07:39 +01:00
|
|
|
ToYaml,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Viewers
|
|
|
|
bind_command! {
|
|
|
|
Griddle,
|
|
|
|
Table,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Conversions
|
|
|
|
bind_command! {
|
2022-01-16 00:50:11 +01:00
|
|
|
Fmt,
|
2021-12-11 04:07:39 +01:00
|
|
|
Into,
|
2021-12-19 21:11:28 +01:00
|
|
|
IntoBool,
|
2021-12-11 04:07:39 +01:00
|
|
|
IntoBinary,
|
|
|
|
IntoDatetime,
|
|
|
|
IntoDecimal,
|
|
|
|
IntoFilesize,
|
|
|
|
IntoInt,
|
|
|
|
IntoString,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Env
|
|
|
|
bind_command! {
|
2022-01-16 00:50:11 +01:00
|
|
|
Env,
|
2021-12-11 04:07:39 +01:00
|
|
|
LetEnv,
|
2022-01-16 00:50:11 +01:00
|
|
|
LoadEnv,
|
2021-11-04 03:32:35 +01:00
|
|
|
WithEnv,
|
2021-12-11 04:07:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Math
|
|
|
|
bind_command! {
|
|
|
|
Math,
|
|
|
|
MathAbs,
|
|
|
|
MathAvg,
|
|
|
|
MathCeil,
|
|
|
|
MathEval,
|
|
|
|
MathFloor,
|
|
|
|
MathMax,
|
|
|
|
MathMedian,
|
|
|
|
MathMin,
|
|
|
|
MathMode,
|
|
|
|
MathProduct,
|
|
|
|
MathRound,
|
|
|
|
MathSqrt,
|
|
|
|
MathStddev,
|
|
|
|
MathSum,
|
|
|
|
MathVariance,
|
|
|
|
};
|
|
|
|
|
2021-12-12 20:42:04 +01:00
|
|
|
// Network
|
|
|
|
bind_command! {
|
2022-01-06 00:06:16 +01:00
|
|
|
Fetch,
|
2021-12-12 20:42:04 +01:00
|
|
|
Url,
|
|
|
|
UrlHost,
|
|
|
|
UrlPath,
|
|
|
|
UrlQuery,
|
|
|
|
UrlScheme,
|
|
|
|
}
|
|
|
|
|
2021-12-11 04:07:39 +01:00
|
|
|
// Random
|
|
|
|
bind_command! {
|
|
|
|
Random,
|
2021-12-12 20:42:04 +01:00
|
|
|
RandomBool,
|
|
|
|
RandomChars,
|
|
|
|
RandomDecimal,
|
|
|
|
RandomDice,
|
|
|
|
RandomInteger,
|
|
|
|
RandomUuid,
|
2021-12-11 04:07:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Generators
|
|
|
|
bind_command! {
|
|
|
|
Cal,
|
2022-01-16 14:52:41 +01:00
|
|
|
Seq,
|
2022-01-14 23:07:28 +01:00
|
|
|
SeqDate,
|
2021-12-11 04:07:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Hash
|
|
|
|
bind_command! {
|
2021-12-11 00:14:28 +01:00
|
|
|
Hash,
|
|
|
|
HashMd5::default(),
|
|
|
|
HashSha256::default(),
|
2022-01-22 17:23:55 +01:00
|
|
|
Base64,
|
2021-12-11 04:07:39 +01:00
|
|
|
};
|
2021-09-03 04:15:01 +02:00
|
|
|
|
2021-11-02 21:56:00 +01:00
|
|
|
#[cfg(feature = "plugin")]
|
|
|
|
bind_command!(Register);
|
|
|
|
|
2021-09-14 06:59:46 +02:00
|
|
|
// 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()
|
|
|
|
};
|
|
|
|
|
2022-01-04 23:30:34 +01:00
|
|
|
let _ = engine_state.merge_delta(delta, None, &cwd);
|
2021-09-03 00:58:15 +02:00
|
|
|
|
|
|
|
engine_state
|
|
|
|
}
|