mirror of
https://github.com/nushell/nushell.git
synced 2025-02-18 11:31:14 +01:00
# Description Now that we've landed the debug commands we were working on, let's relocate them to an easier place to find all of them. That's what this PR does. The only actual code change was changing the `timeit` command to a `Category::Debug` command. The rest is just moving things around and hooking them up. # User-Facing Changes # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
510 lines
10 KiB
Rust
510 lines
10 KiB
Rust
use nu_protocol::engine::{EngineState, StateWorkingSet};
|
|
|
|
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)); )*
|
|
};
|
|
}
|
|
|
|
// 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);
|
|
|
|
// Database-related
|
|
// Adds all related commands to query databases
|
|
#[cfg(feature = "sqlite")]
|
|
add_database_decls(&mut working_set);
|
|
|
|
// Core
|
|
bind_command! {
|
|
Alias,
|
|
Ast,
|
|
Break,
|
|
Commandline,
|
|
Const,
|
|
Continue,
|
|
Def,
|
|
DefEnv,
|
|
Describe,
|
|
Do,
|
|
Echo,
|
|
ErrorMake,
|
|
ExportAlias,
|
|
ExportCommand,
|
|
ExportDef,
|
|
ExportDefEnv,
|
|
ExportExtern,
|
|
ExportUse,
|
|
Extern,
|
|
For,
|
|
Help,
|
|
HelpAliases,
|
|
HelpCommands,
|
|
HelpModules,
|
|
HelpOperators,
|
|
Hide,
|
|
HideEnv,
|
|
If,
|
|
Ignore,
|
|
Overlay,
|
|
OverlayUse,
|
|
OverlayList,
|
|
OverlayNew,
|
|
OverlayHide,
|
|
Let,
|
|
Loop,
|
|
Module,
|
|
Mut,
|
|
Return,
|
|
Try,
|
|
Use,
|
|
Version,
|
|
While,
|
|
};
|
|
|
|
// Charts
|
|
bind_command! {
|
|
Histogram
|
|
}
|
|
|
|
// Filters
|
|
bind_command! {
|
|
All,
|
|
Any,
|
|
Append,
|
|
Collect,
|
|
Columns,
|
|
Compact,
|
|
Default,
|
|
Drop,
|
|
DropColumn,
|
|
DropNth,
|
|
Each,
|
|
EachWhile,
|
|
Empty,
|
|
Enumerate,
|
|
Every,
|
|
Filter,
|
|
Find,
|
|
First,
|
|
Flatten,
|
|
Get,
|
|
Group,
|
|
GroupBy,
|
|
Headers,
|
|
Insert,
|
|
SplitBy,
|
|
Take,
|
|
Merge,
|
|
Move,
|
|
TakeWhile,
|
|
TakeUntil,
|
|
Last,
|
|
Length,
|
|
Lines,
|
|
ParEach,
|
|
Prepend,
|
|
Range,
|
|
Reduce,
|
|
Reject,
|
|
Rename,
|
|
Reverse,
|
|
Roll,
|
|
RollDown,
|
|
RollUp,
|
|
RollLeft,
|
|
RollRight,
|
|
Rotate,
|
|
Select,
|
|
Shuffle,
|
|
Skip,
|
|
SkipUntil,
|
|
SkipWhile,
|
|
Sort,
|
|
SortBy,
|
|
SplitList,
|
|
Transpose,
|
|
Uniq,
|
|
UniqBy,
|
|
Upsert,
|
|
Update,
|
|
UpdateCells,
|
|
Values,
|
|
Where,
|
|
Window,
|
|
Wrap,
|
|
Zip,
|
|
};
|
|
|
|
// Misc
|
|
bind_command! {
|
|
History,
|
|
Tutor,
|
|
HistorySession,
|
|
};
|
|
|
|
// Path
|
|
bind_command! {
|
|
Path,
|
|
PathBasename,
|
|
PathDirname,
|
|
PathExists,
|
|
PathExpand,
|
|
PathJoin,
|
|
PathParse,
|
|
PathRelativeTo,
|
|
PathSplit,
|
|
PathType,
|
|
};
|
|
|
|
// System
|
|
bind_command! {
|
|
Complete,
|
|
External,
|
|
NuCheck,
|
|
Sys,
|
|
};
|
|
|
|
// Debug
|
|
bind_command! {
|
|
Debug,
|
|
Explain,
|
|
Inspect,
|
|
Metadata,
|
|
Profile,
|
|
TimeIt,
|
|
View,
|
|
ViewFiles,
|
|
ViewSource,
|
|
ViewSpan,
|
|
};
|
|
|
|
#[cfg(unix)]
|
|
bind_command! { Exec }
|
|
|
|
#[cfg(windows)]
|
|
bind_command! { RegistryQuery }
|
|
|
|
#[cfg(any(
|
|
target_os = "android",
|
|
target_os = "linux",
|
|
target_os = "macos",
|
|
target_os = "windows"
|
|
))]
|
|
bind_command! { Ps };
|
|
|
|
#[cfg(feature = "which-support")]
|
|
bind_command! { Which };
|
|
|
|
// Strings
|
|
bind_command! {
|
|
Char,
|
|
Decode,
|
|
Encode,
|
|
DecodeBase64,
|
|
EncodeBase64,
|
|
DetectColumns,
|
|
Format,
|
|
FileSize,
|
|
Parse,
|
|
Size,
|
|
Split,
|
|
SplitChars,
|
|
SplitColumn,
|
|
SplitRow,
|
|
SplitWords,
|
|
Str,
|
|
StrCamelCase,
|
|
StrCapitalize,
|
|
StrCollect,
|
|
StrContains,
|
|
StrDistance,
|
|
StrDowncase,
|
|
StrEndswith,
|
|
StrJoin,
|
|
StrReplace,
|
|
StrIndexOf,
|
|
StrKebabCase,
|
|
StrLength,
|
|
StrPascalCase,
|
|
StrReverse,
|
|
StrScreamingSnakeCase,
|
|
StrSnakeCase,
|
|
StrStartsWith,
|
|
StrSubstring,
|
|
StrTrim,
|
|
StrTitleCase,
|
|
StrUpcase
|
|
};
|
|
|
|
// Bits
|
|
bind_command! {
|
|
Bits,
|
|
BitsAnd,
|
|
BitsNot,
|
|
BitsOr,
|
|
BitsXor,
|
|
BitsRotateLeft,
|
|
BitsRotateRight,
|
|
BitsShiftLeft,
|
|
BitsShiftRight,
|
|
}
|
|
|
|
// Bytes
|
|
bind_command! {
|
|
Bytes,
|
|
BytesLen,
|
|
BytesStartsWith,
|
|
BytesEndsWith,
|
|
BytesReverse,
|
|
BytesReplace,
|
|
BytesAdd,
|
|
BytesAt,
|
|
BytesIndexOf,
|
|
BytesCollect,
|
|
BytesRemove,
|
|
BytesBuild,
|
|
}
|
|
|
|
// FileSystem
|
|
bind_command! {
|
|
Cd,
|
|
Cp,
|
|
Ls,
|
|
Mkdir,
|
|
Mv,
|
|
Open,
|
|
Start,
|
|
Rm,
|
|
Save,
|
|
Touch,
|
|
Glob,
|
|
Watch,
|
|
};
|
|
|
|
// Platform
|
|
bind_command! {
|
|
Ansi,
|
|
AnsiGradient,
|
|
AnsiStrip,
|
|
AnsiLink,
|
|
Clear,
|
|
Du,
|
|
KeybindingsDefault,
|
|
Input,
|
|
KeybindingsListen,
|
|
Keybindings,
|
|
Kill,
|
|
KeybindingsList,
|
|
Sleep,
|
|
TermSize,
|
|
};
|
|
|
|
// Date
|
|
bind_command! {
|
|
Date,
|
|
DateFormat,
|
|
DateHumanize,
|
|
DateListTimezones,
|
|
DateNow,
|
|
DateToRecord,
|
|
DateToTable,
|
|
DateToTimezone,
|
|
};
|
|
|
|
// Shells
|
|
bind_command! {
|
|
Enter,
|
|
Exit,
|
|
GotoShell,
|
|
NextShell,
|
|
PrevShell,
|
|
Shells,
|
|
};
|
|
|
|
// Formats
|
|
bind_command! {
|
|
From,
|
|
FromCsv,
|
|
FromJson,
|
|
FromNuon,
|
|
FromOds,
|
|
FromSsv,
|
|
FromToml,
|
|
FromTsv,
|
|
FromUrl,
|
|
FromXlsx,
|
|
FromXml,
|
|
FromYaml,
|
|
FromYml,
|
|
To,
|
|
ToCsv,
|
|
ToHtml,
|
|
ToJson,
|
|
ToMd,
|
|
ToNuon,
|
|
ToText,
|
|
ToToml,
|
|
ToTsv,
|
|
Touch,
|
|
Use,
|
|
Upsert,
|
|
Where,
|
|
ToXml,
|
|
ToYaml,
|
|
};
|
|
|
|
// Viewers
|
|
bind_command! {
|
|
Griddle,
|
|
Table,
|
|
Explore,
|
|
};
|
|
|
|
// Conversions
|
|
bind_command! {
|
|
Fill,
|
|
Fmt,
|
|
Into,
|
|
IntoBool,
|
|
IntoBinary,
|
|
IntoDatetime,
|
|
IntoDecimal,
|
|
IntoDuration,
|
|
IntoFilesize,
|
|
IntoInt,
|
|
IntoRecord,
|
|
IntoString,
|
|
};
|
|
|
|
// Env
|
|
bind_command! {
|
|
Env,
|
|
ExportEnv,
|
|
LetEnv,
|
|
LoadEnv,
|
|
SourceEnv,
|
|
WithEnv,
|
|
ConfigNu,
|
|
ConfigEnv,
|
|
ConfigMeta,
|
|
ConfigReset,
|
|
};
|
|
|
|
// Math
|
|
bind_command! {
|
|
Math,
|
|
MathAbs,
|
|
MathAvg,
|
|
MathCeil,
|
|
MathFloor,
|
|
MathMax,
|
|
MathMedian,
|
|
MathMin,
|
|
MathMode,
|
|
MathProduct,
|
|
MathRound,
|
|
MathSqrt,
|
|
MathStddev,
|
|
MathSum,
|
|
MathVariance,
|
|
MathSin,
|
|
MathCos,
|
|
MathTan,
|
|
MathSinH,
|
|
MathCosH,
|
|
MathTanH,
|
|
MathArcSin,
|
|
MathArcCos,
|
|
MathArcTan,
|
|
MathArcSinH,
|
|
MathArcCosH,
|
|
MathArcTanH,
|
|
MathPi,
|
|
MathTau,
|
|
MathEuler,
|
|
MathLn,
|
|
MathLog,
|
|
};
|
|
|
|
// Network
|
|
bind_command! {
|
|
Http,
|
|
HttpGet,
|
|
HttpPost,
|
|
Url,
|
|
UrlBuildQuery,
|
|
UrlEncode,
|
|
UrlJoin,
|
|
UrlParse,
|
|
Port,
|
|
}
|
|
|
|
// Random
|
|
bind_command! {
|
|
Random,
|
|
RandomBool,
|
|
RandomChars,
|
|
RandomDecimal,
|
|
RandomDice,
|
|
RandomInteger,
|
|
RandomUuid,
|
|
};
|
|
|
|
// Generators
|
|
bind_command! {
|
|
Cal,
|
|
Seq,
|
|
SeqDate,
|
|
SeqChar,
|
|
};
|
|
|
|
// Hash
|
|
bind_command! {
|
|
Hash,
|
|
HashMd5::default(),
|
|
HashSha256::default(),
|
|
};
|
|
|
|
// Experimental
|
|
bind_command! {
|
|
IsAdmin,
|
|
};
|
|
|
|
// Deprecated
|
|
bind_command! {
|
|
HashBase64,
|
|
LPadDeprecated,
|
|
RPadDeprecated,
|
|
Source,
|
|
StrDatetimeDeprecated,
|
|
StrDecimalDeprecated,
|
|
StrIntDeprecated,
|
|
StrFindReplaceDeprecated,
|
|
MathEvalDeprecated,
|
|
};
|
|
|
|
#[cfg(feature = "plugin")]
|
|
bind_command!(Register);
|
|
|
|
working_set.render()
|
|
};
|
|
|
|
if let Err(err) = engine_state.merge_delta(delta) {
|
|
eprintln!("Error creating default context: {err:?}");
|
|
}
|
|
|
|
engine_state
|
|
}
|