REFACTOR: move the 0% commands to nu-cmd-extra (#9404)

requires
- https://github.com/nushell/nushell/pull/9455

# ⚙️ Description
in this PR i move the commands we've all agreed, in the core team, to
move out of the core Nushell to the `extra` feature.

> **Warning**
> in the first commits here, i've
> - moved the implementations to `nu-cmd-extra`
> - removed the declaration of all the commands below from `nu-command`
> - made sure the commands were not available anymore with `cargo run --
-n`

## the list of commands to move
with the current command table downloaded as `commands.csv`, i've run
```bash
let commands = (
    open commands.csv
    | where is_plugin == "FALSE" and category != "deprecated"
    | select name category "approv. %"
    | rename name category approval
    | insert treated {|it| (
        ($it.approval == 100) or                # all the core team agreed on them
        ($it.name | str starts-with "bits") or  # see https://github.com/nushell/nushell/pull/9241
        ($it.name | str starts-with "dfr")      # see https://github.com/nushell/nushell/pull/9327
    )}
)
```
to preprocess them and then
```bash
$commands | where {|it| (not $it.treated) and ($it.approval == 0)}
```
to get all untreated commands with no approval, which gives
```
╭────┬───────────────┬─────────┬─────────────┬──────────╮
│  # │     name      │ treated │  category   │ approval │
├────┼───────────────┼─────────┼─────────────┼──────────┤
│  0 │ fmt           │ false   │ conversions │        0 │
│  1 │ each while    │ false   │ filters     │        0 │
│  2 │ roll          │ false   │ filters     │        0 │
│  3 │ roll down     │ false   │ filters     │        0 │
│  4 │ roll left     │ false   │ filters     │        0 │
│  5 │ roll right    │ false   │ filters     │        0 │
│  6 │ roll up       │ false   │ filters     │        0 │
│  7 │ rotate        │ false   │ filters     │        0 │
│  8 │ update cells  │ false   │ filters     │        0 │
│  9 │ decode hex    │ false   │ formats     │        0 │
│ 10 │ encode hex    │ false   │ formats     │        0 │
│ 11 │ from url      │ false   │ formats     │        0 │
│ 12 │ to html       │ false   │ formats     │        0 │
│ 13 │ ansi gradient │ false   │ platform    │        0 │
│ 14 │ ansi link     │ false   │ platform    │        0 │
│ 15 │ format        │ false   │ strings     │        0 │
╰────┴───────────────┴─────────┴─────────────┴──────────╯
```
# 🖌️ User-Facing Changes
```
$nothing
```

# 🧪 Tests + Formatting
-  `toolkit fmt`
-  `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`

# 📖 After Submitting
```
$nothing
```

# 🔍 For reviewers
```bash
$commands | where {|it| (not $it.treated) and ($it.approval == 0)} | each {|command|
    try {
        help $command.name | ignore
    } catch {|e|
        $"($command.name): ($e.msg)"
    }
}
```
should give no output in `cargo run --features extra -- -n` and a table
with 16 lines in `cargo run -- -n`
This commit is contained in:
Antoine Stevan
2023-07-06 17:31:31 +02:00
committed by GitHub
parent fbc1408913
commit 504eff73f0
56 changed files with 558 additions and 448 deletions

819
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,3 +13,4 @@ version = "0.82.1"
nu-engine = { path = "../nu-engine", version = "0.82.1" } nu-engine = { path = "../nu-engine", version = "0.82.1" }
nu-path = { path = "../nu-path", version = "0.82.1" } nu-path = { path = "../nu-path", version = "0.82.1" }
nu-protocol = { version = "0.82.1", path = "../nu-protocol" } nu-protocol = { version = "0.82.1", path = "../nu-protocol" }
indexmap = { version = "1.7", features = ["serde-1"] }

View File

@ -0,0 +1 @@
pub mod to;

View File

@ -0,0 +1,20 @@
use indexmap::{indexset, IndexSet};
use nu_protocol::Value;
pub fn merge_descriptors(values: &[Value]) -> Vec<String> {
let mut ret: Vec<String> = vec![];
let mut seen: IndexSet<String> = indexset! {};
for value in values {
let data_descriptors = match value {
Value::Record { cols, .. } => cols.to_owned(),
_ => vec!["".to_string()],
};
for desc in data_descriptors {
if !desc.is_empty() && !seen.contains(&desc) {
seen.insert(desc.to_string());
ret.push(desc.to_string());
}
}
}
ret
}

View File

@ -0,0 +1 @@
pub mod delimited;

View File

@ -1,2 +1,3 @@
pub mod formats;
pub mod input_handler; pub mod input_handler;
pub mod util; pub mod util;

View File

@ -21,6 +21,15 @@ nu-utils = { path = "../nu-utils", version = "0.82.1" }
# Potential dependencies for extras # Potential dependencies for extras
num-traits = "0.2" num-traits = "0.2"
ahash = "0.8.3"
nu-ansi-term = "0.48.0"
fancy-regex = "0.11.0"
rust-embed = "6.7.0"
serde = "1.0.164"
nu-pretty-hex = { version = "0.82.1", path = "../nu-pretty-hex" }
nu-json = { version = "0.82.1", path = "../nu-json" }
serde_urlencoded = "0.7.1"
htmlescape = "0.3.1"
[features] [features]
extra = ["default"] extra = ["default"]
@ -28,4 +37,5 @@ default = []
[dev-dependencies] [dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.82.1" } nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.82.1" }
nu-command = { path = "../nu-command", version = "0.82.1" }
nu-test-support = { path = "../nu-test-support", version = "0.82.1" } nu-test-support = { path = "../nu-test-support", version = "0.82.1" }

View File

@ -61,6 +61,9 @@ mod test_examples {
// Try to keep this working set small to keep tests running as fast as possible // Try to keep this working set small to keep tests running as fast as possible
let mut working_set = StateWorkingSet::new(&engine_state); let mut working_set = StateWorkingSet::new(&engine_state);
working_set.add_decl(Box::new(nu_command::Enumerate));
working_set.add_decl(Box::new(nu_cmd_lang::If));
// Adding the command that is being tested to the working set // Adding the command that is being tested to the working set
working_set.add_decl(cmd); working_set.add_decl(cmd);
working_set.render() working_set.render()

View File

@ -0,0 +1,3 @@
mod fmt;
pub(crate) use fmt::Fmt;

View File

@ -0,0 +1,9 @@
mod each_while;
mod roll;
mod rotate;
mod update_cells;
pub(crate) use each_while::EachWhile;
pub(crate) use roll::*;
pub(crate) use rotate::Rotate;
pub(crate) use update_cells::UpdateCells;

View File

@ -0,0 +1 @@
pub(crate) mod url;

View File

@ -0,0 +1,5 @@
mod from;
mod to;
pub(crate) use from::url::FromUrl;
pub(crate) use to::html::ToHtml;

View File

@ -1,5 +1,5 @@
use crate::formats::to::delimited::merge_descriptors;
use fancy_regex::Regex; use fancy_regex::Regex;
use nu_cmd_base::formats::to::delimited::merge_descriptors;
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};

View File

@ -0,0 +1 @@
pub(crate) mod html;

View File

@ -1,5 +1,10 @@
mod bits; mod bits;
mod bytes; mod bytes;
mod conversions;
mod filters;
mod formats;
mod platform;
mod strings;
pub use bytes::Bytes; pub use bytes::Bytes;
pub use bytes::BytesAdd; pub use bytes::BytesAdd;
@ -40,6 +45,29 @@ pub fn add_extra_command_context(mut engine_state: EngineState) -> EngineState {
}; };
} }
bind_command!(conversions::Fmt);
bind_command!(
filters::UpdateCells,
filters::EachWhile,
filters::Roll,
filters::RollDown,
filters::RollUp,
filters::RollLeft,
filters::RollRight,
filters::Rotate
);
bind_command!(platform::ansi::Gradient, platform::ansi::Link);
bind_command!(
strings::format::Format,
strings::format::FileSize,
strings::encode_decode::EncodeHex,
strings::encode_decode::DecodeHex
);
bind_command!(formats::ToHtml, formats::FromUrl);
// Bits // Bits
bind_command! { bind_command! {
Bits, Bits,

View File

@ -0,0 +1,5 @@
mod gradient;
mod link;
pub(crate) use gradient::SubCommand as Gradient;
pub(crate) use link::SubCommand as Link;

View File

@ -0,0 +1 @@
pub(crate) mod ansi;

View File

@ -0,0 +1,6 @@
mod decode_hex;
mod encode_hex;
mod hex;
pub(crate) use decode_hex::DecodeHex;
pub(crate) use encode_hex::EncodeHex;

View File

@ -0,0 +1,5 @@
mod command;
mod filesize;
pub(crate) use command::Format;
pub(crate) use filesize::FileSize;

View File

@ -0,0 +1,2 @@
pub(crate) mod encode_decode;
pub(crate) mod format;

View File

@ -77,7 +77,6 @@ rayon = "1.7"
regex = "1.7" regex = "1.7"
roxmltree = "0.18" roxmltree = "0.18"
rusqlite = { version = "0.29", features = ["bundled"], optional = true } rusqlite = { version = "0.29", features = ["bundled"], optional = true }
rust-embed = "6.7"
same-file = "1.0" same-file = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"

View File

@ -1,7 +1,5 @@
mod fill; mod fill;
mod fmt;
pub(crate) mod into; pub(crate) mod into;
pub use fill::Fill; pub use fill::Fill;
pub use fmt::Fmt;
pub use into::*; pub use into::*;

View File

@ -41,7 +41,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
DropColumn, DropColumn,
DropNth, DropNth,
Each, Each,
EachWhile,
Empty, Empty,
Enumerate, Enumerate,
Every, Every,
@ -72,12 +71,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
Reject, Reject,
Rename, Rename,
Reverse, Reverse,
Roll,
RollDown,
RollUp,
RollLeft,
RollRight,
Rotate,
Select, Select,
Shuffle, Shuffle,
Skip, Skip,
@ -91,7 +84,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
UniqBy, UniqBy,
Upsert, Upsert,
Update, Update,
UpdateCells,
Values, Values,
Where, Where,
Window, Window,
@ -176,11 +168,7 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
Encode, Encode,
DecodeBase64, DecodeBase64,
EncodeBase64, EncodeBase64,
DecodeHex,
EncodeHex,
DetectColumns, DetectColumns,
Format,
FileSize,
Parse, Parse,
Size, Size,
Split, Split,
@ -231,9 +219,7 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
// Platform // Platform
bind_command! { bind_command! {
Ansi, Ansi,
AnsiGradient,
AnsiStrip, AnsiStrip,
AnsiLink,
Clear, Clear,
Du, Du,
Input, Input,
@ -271,14 +257,12 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
FromSsv, FromSsv,
FromToml, FromToml,
FromTsv, FromTsv,
FromUrl,
FromXlsx, FromXlsx,
FromXml, FromXml,
FromYaml, FromYaml,
FromYml, FromYml,
To, To,
ToCsv, ToCsv,
ToHtml,
ToJson, ToJson,
ToMd, ToMd,
ToNuon, ToNuon,
@ -301,7 +285,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
// Conversions // Conversions
bind_command! { bind_command! {
Fill, Fill,
Fmt,
Into, Into,
IntoBool, IntoBool,
IntoBinary, IntoBinary,

View File

@ -6,7 +6,6 @@ mod compact;
mod default; mod default;
mod drop; mod drop;
mod each; mod each;
mod each_while;
mod empty; mod empty;
mod enumerate; mod enumerate;
mod every; mod every;
@ -33,8 +32,6 @@ mod reduce;
mod reject; mod reject;
mod rename; mod rename;
mod reverse; mod reverse;
mod roll;
mod rotate;
mod select; mod select;
mod shuffle; mod shuffle;
mod skip; mod skip;
@ -46,7 +43,6 @@ mod transpose;
mod uniq; mod uniq;
mod uniq_by; mod uniq_by;
mod update; mod update;
mod update_cells;
mod upsert; mod upsert;
mod utils; mod utils;
mod values; mod values;
@ -63,7 +59,6 @@ pub use compact::Compact;
pub use default::Default; pub use default::Default;
pub use drop::*; pub use drop::*;
pub use each::Each; pub use each::Each;
pub use each_while::EachWhile;
pub use empty::Empty; pub use empty::Empty;
pub use enumerate::Enumerate; pub use enumerate::Enumerate;
pub use every::Every; pub use every::Every;
@ -90,8 +85,6 @@ pub use reduce::Reduce;
pub use reject::Reject; pub use reject::Reject;
pub use rename::Rename; pub use rename::Rename;
pub use reverse::Reverse; pub use reverse::Reverse;
pub use roll::*;
pub use rotate::Rotate;
pub use select::Select; pub use select::Select;
pub use shuffle::Shuffle; pub use shuffle::Shuffle;
pub use skip::*; pub use skip::*;
@ -103,7 +96,6 @@ pub use transpose::Transpose;
pub use uniq::*; pub use uniq::*;
pub use uniq_by::UniqBy; pub use uniq_by::UniqBy;
pub use update::Update; pub use update::Update;
pub use update_cells::UpdateCells;
pub use upsert::Upsert; pub use upsert::Upsert;
pub use values::Values; pub use values::Values;
pub use where_::Where; pub use where_::Where;

View File

@ -7,14 +7,12 @@ mod ods;
mod ssv; mod ssv;
mod toml; mod toml;
mod tsv; mod tsv;
mod url;
mod xlsx; mod xlsx;
mod xml; mod xml;
mod yaml; mod yaml;
pub use self::csv::FromCsv; pub use self::csv::FromCsv;
pub use self::toml::FromToml; pub use self::toml::FromToml;
pub use self::url::FromUrl;
pub use command::From; pub use command::From;
pub use json::FromJson; pub use json::FromJson;
pub use nuon::FromNuon; pub use nuon::FromNuon;

View File

@ -1,5 +1,5 @@
use csv::{Writer, WriterBuilder}; use csv::{Writer, WriterBuilder};
use indexmap::{indexset, IndexSet}; use nu_cmd_base::formats::to::delimited::merge_descriptors;
use nu_protocol::{Config, IntoPipelineData, PipelineData, ShellError, Span, Value}; use nu_protocol::{Config, IntoPipelineData, PipelineData, ShellError, Span, Value};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::error::Error; use std::error::Error;
@ -142,24 +142,6 @@ pub fn find_non_record(values: &[Value]) -> Option<&Value> {
.find(|val| !matches!(val, Value::Record { .. })) .find(|val| !matches!(val, Value::Record { .. }))
} }
pub fn merge_descriptors(values: &[Value]) -> Vec<String> {
let mut ret: Vec<String> = vec![];
let mut seen: IndexSet<String> = indexset! {};
for value in values {
let data_descriptors = match value {
Value::Record { cols, .. } => cols.to_owned(),
_ => vec!["".to_string()],
};
for desc in data_descriptors {
if !desc.is_empty() && !seen.contains(&desc) {
seen.insert(desc.to_string());
ret.push(desc.to_string());
}
}
}
ret
}
pub fn to_delimited_data( pub fn to_delimited_data(
noheaders: bool, noheaders: bool,
sep: char, sep: char,

View File

@ -1,5 +1,5 @@
use crate::formats::to::delimited::merge_descriptors;
use indexmap::map::IndexMap; use indexmap::map::IndexMap;
use nu_cmd_base::formats::to::delimited::merge_descriptors;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{

View File

@ -1,7 +1,6 @@
mod command; mod command;
mod csv; mod csv;
mod delimited; mod delimited;
mod html;
mod json; mod json;
mod md; mod md;
mod nuon; mod nuon;
@ -14,7 +13,6 @@ mod yaml;
pub use self::csv::ToCsv; pub use self::csv::ToCsv;
pub use self::toml::ToToml; pub use self::toml::ToToml;
pub use command::To; pub use command::To;
pub use html::ToHtml;
pub use json::ToJson; pub use json::ToJson;
pub use md::ToMd; pub use md::ToMd;
pub use nuon::value_to_string; pub use nuon::value_to_string;

View File

@ -1,9 +1,5 @@
mod ansi_; mod ansi_;
mod gradient;
mod link;
mod strip; mod strip;
pub use ansi_::AnsiCommand as Ansi; pub use ansi_::AnsiCommand as Ansi;
pub use gradient::SubCommand as AnsiGradient;
pub use link::SubCommand as AnsiLink;
pub use strip::SubCommand as AnsiStrip; pub use strip::SubCommand as AnsiStrip;

View File

@ -7,7 +7,7 @@ mod kill;
mod sleep; mod sleep;
mod term_size; mod term_size;
pub use ansi::{Ansi, AnsiGradient, AnsiLink, AnsiStrip}; pub use ansi::{Ansi, AnsiStrip};
pub use clear::Clear; pub use clear::Clear;
pub use dir_info::{DirBuilder, DirInfo, FileInfo}; pub use dir_info::{DirBuilder, DirInfo, FileInfo};
pub use du::Du; pub use du::Du;

View File

@ -1,16 +1,11 @@
mod base64; mod base64;
mod decode; mod decode;
mod decode_base64; mod decode_base64;
mod decode_hex;
mod encode; mod encode;
mod encode_base64; mod encode_base64;
mod encode_hex;
mod encoding; mod encoding;
mod hex;
pub use self::decode::Decode; pub use self::decode::Decode;
pub use self::decode_base64::DecodeBase64; pub use self::decode_base64::DecodeBase64;
pub use self::decode_hex::DecodeHex;
pub use self::encode::Encode; pub use self::encode::Encode;
pub use self::encode_base64::EncodeBase64; pub use self::encode_base64::EncodeBase64;
pub use self::encode_hex::EncodeHex;

View File

@ -1,5 +0,0 @@
mod command;
mod filesize;
pub use self::filesize::FileSize;
pub use command::Format;

View File

@ -1,7 +1,6 @@
mod char_; mod char_;
mod detect_columns; mod detect_columns;
mod encode_decode; mod encode_decode;
mod format;
mod parse; mod parse;
mod size; mod size;
mod split; mod split;
@ -10,7 +9,6 @@ mod str_;
pub use char_::Char; pub use char_::Char;
pub use detect_columns::*; pub use detect_columns::*;
pub use encode_decode::*; pub use encode_decode::*;
pub use format::*;
pub use parse::*; pub use parse::*;
pub use size::Size; pub use size::Size;
pub use split::*; pub use split::*;

View File

@ -52,6 +52,7 @@ fn each_uses_enumerate_index() {
} }
#[test] #[test]
#[cfg(feature = "extra")]
fn each_while_uses_enumerate_index() { fn each_while_uses_enumerate_index() {
let actual = nu!("[7 8 9 10] | enumerate | each while {|el| $el.index } | to nuon"); let actual = nu!("[7 8 9 10] | enumerate | each while {|el| $el.index } | to nuon");

View File

@ -27,6 +27,7 @@ mod find;
mod first; mod first;
mod flatten; mod flatten;
mod for_; mod for_;
#[cfg(feature = "extra")]
mod format; mod format;
mod get; mod get;
mod glob; mod glob;
@ -72,7 +73,9 @@ mod rename;
mod return_; mod return_;
mod reverse; mod reverse;
mod rm; mod rm;
#[cfg(feature = "extra")]
mod roll; mod roll;
#[cfg(feature = "extra")]
mod rotate; mod rotate;
mod run_external; mod run_external;
mod save; mod save;

View File

@ -1,5 +1,6 @@
mod bson; mod bson;
mod csv; mod csv;
#[cfg(feature = "extra")]
mod html; mod html;
mod json; mod json;
mod markdown; mod markdown;
@ -8,6 +9,7 @@ mod ods;
mod ssv; mod ssv;
mod toml; mod toml;
mod tsv; mod tsv;
#[cfg(feature = "extra")]
mod url; mod url;
mod xlsx; mod xlsx;
mod xml; mod xml;

View File

@ -54,7 +54,9 @@ fn in_and_if_else() -> TestResult {
#[test] #[test]
fn help_works_with_missing_requirements() -> TestResult { fn help_works_with_missing_requirements() -> TestResult {
run_test(r#"each --help | lines | length"#, "65") // `each while` is part of the *extra* feature and adds 3 lines
let expected_length = if cfg!(feature = "extra") { "65" } else { "62" };
run_test(r#"each --help | lines | length"#, expected_length)
} }
#[test] #[test]