Sort default context items categorically (#465)

* Sort default context items categorically

* Separate commands in multiple statements

* Use curly braces instead of square brackets

This prevents undesired reformatting.
This commit is contained in:
Benoît Cortier 2021-12-10 22:07:39 -05:00 committed by GitHub
parent 3df5e63c05
commit d0119ea05d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 169 additions and 108 deletions

View file

@ -1,14 +1,13 @@
use std::collections::VecDeque;
use chrono::{Datelike, Local, NaiveDate}; use chrono::{Datelike, Local, NaiveDate};
use indexmap::IndexMap; use indexmap::IndexMap;
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
ast::Call, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned,
engine::{Command, EngineState, Stack}, SyntaxShape, Value,
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
Value,
}; };
use std::collections::VecDeque;
#[derive(Clone)] #[derive(Clone)]
pub struct Cal; pub struct Cal;
@ -49,6 +48,7 @@ impl Command for Cal {
"Display the month names instead of integers", "Display the month names instead of integers",
None, None,
) )
.category(Category::Generators)
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View file

@ -21,113 +21,72 @@ pub fn create_default_context() -> EngineState {
#[cfg(feature = "dataframe")] #[cfg(feature = "dataframe")]
add_dataframe_decls(&mut working_set); add_dataframe_decls(&mut working_set);
// TODO: sort default context items categorically // Core
bind_command!( bind_command! {
Alias, Alias,
All,
Any,
Append,
Benchmark,
BuildString,
Cal,
Cd,
Clear,
Collect,
Cp,
Date,
DateFormat,
DateHumanize,
DateListTimezones,
DateNow,
DateToTable,
DateToTimezone,
Debug, Debug,
Def, Def,
Describe, Describe,
Do, Do,
Drop,
Each,
Echo, Echo,
Exit,
ExportCommand, ExportCommand,
ExportDef, ExportDef,
ExportEnv, ExportEnv,
External,
First,
For, For,
Format,
From,
FromCsv,
FromJson,
FromYaml,
FromYml,
FromTsv,
FromToml,
FromUrl,
FromEml,
FromOds,
FromIcs,
FromIni,
FromVcf,
FromSsv,
FromXml,
FromXlsx,
Get,
Griddle,
Help, Help,
Hide, Hide,
If, If,
Into, Let,
IntoBinary, Module,
IntoDatetime, Source,
IntoDecimal, Use,
IntoFilesize, };
IntoInt,
IntoString, // Filters
Kill, bind_command! {
All,
Any,
Append,
Collect,
Drop,
Each,
First,
Get,
Last, Last,
Length, Length,
Let,
LetEnv,
Lines, Lines,
Ls,
Math,
MathAbs,
MathAvg,
MathCeil,
MathFloor,
MathEval,
MathMax,
MathMedian,
MathMin,
MathMode,
MathProduct,
MathRound,
MathSqrt,
MathStddev,
MathSum,
MathVariance,
Mkdir,
Module,
Mv,
Nth, Nth,
ParEach, ParEach,
Parse,
Prepend, Prepend,
Ps,
Range, Range,
Random,
Reject, Reject,
Reverse, Reverse,
Rm,
Select, Select,
Shuffle, Shuffle,
Size,
Skip, Skip,
SkipUntil, SkipUntil,
SkipWhile, SkipWhile,
Sleep, Uniq,
Source, Update,
Where,
Wrap,
Zip,
};
// System
bind_command! {
Benchmark,
External,
Ps,
Sys,
};
// Strings
bind_command! {
BuildString,
Format,
Parse,
Size,
Split, Split,
SplitChars, SplitChars,
SplitColumn, SplitColumn,
@ -139,45 +98,145 @@ pub fn create_default_context() -> EngineState {
StrContains, StrContains,
StrDowncase, StrDowncase,
StrEndswith, StrEndswith,
StrIndexOf,
StrLength,
StrFindReplace, StrFindReplace,
StrIndexOf,
StrKebabCase, StrKebabCase,
StrLength,
StrLpad,
StrPascalCase, StrPascalCase,
StrReverse,
StrRpad,
StrScreamingSnakeCase, StrScreamingSnakeCase,
StrSnakeCase, StrSnakeCase,
StrLpad,
StrRpad,
StrStartsWith, StrStartsWith,
StrReverse,
StrSubstring, StrSubstring,
StrUpcase,
StrTrim, StrTrim,
Sys, StrUpcase,
Table, };
// FileSystem
bind_command! {
Cd,
Cp,
Ls,
Mkdir,
Mv,
Rm,
Touch,
};
// Platform
bind_command! {
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,
To, To,
ToJson,
ToUrl,
ToToml,
ToTsv,
ToCsv, ToCsv,
ToHtml, ToHtml,
ToJson,
ToMd, ToMd,
ToYaml, ToToml,
ToTsv,
ToUrl,
ToXml, ToXml,
Touch, ToYaml,
Uniq, };
Use,
Update, // Viewers
Where, bind_command! {
Griddle,
Table,
};
// Conversions
bind_command! {
Into,
IntoBinary,
IntoDatetime,
IntoDecimal,
IntoFilesize,
IntoInt,
IntoString,
};
// Env
bind_command! {
LetEnv,
WithEnv, WithEnv,
Wrap, };
Zip,
// Hash // Math
bind_command! {
Math,
MathAbs,
MathAvg,
MathCeil,
MathEval,
MathFloor,
MathMax,
MathMedian,
MathMin,
MathMode,
MathProduct,
MathRound,
MathSqrt,
MathStddev,
MathSum,
MathVariance,
};
// Random
bind_command! {
Random,
};
// Generators
bind_command! {
Cal,
};
// Hash
bind_command! {
Hash, Hash,
HashMd5::default(), HashMd5::default(),
HashSha256::default(), HashSha256::default(),
); };
#[cfg(feature = "plugin")] #[cfg(feature = "plugin")]
bind_command!(Register); bind_command!(Register);

View file

@ -50,6 +50,7 @@ pub enum Category {
System, System,
Viewers, Viewers,
Hash, Hash,
Generators,
Custom(String), Custom(String),
} }
@ -74,6 +75,7 @@ impl std::fmt::Display for Category {
Category::System => "system", Category::System => "system",
Category::Viewers => "viewers", Category::Viewers => "viewers",
Category::Hash => "hash", Category::Hash => "hash",
Category::Generators => "generators",
Category::Custom(name) => name, Category::Custom(name) => name,
}; };