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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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-path = { path = "../nu-path", version = "0.82.1" }
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 util;

View File

@ -21,6 +21,15 @@ nu-utils = { path = "../nu-utils", version = "0.82.1" }
# Potential dependencies for extras
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]
extra = ["default"]
@ -28,4 +37,5 @@ default = []
[dev-dependencies]
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" }

View File

@ -61,6 +61,9 @@ mod test_examples {
// Try to keep this working set small to keep tests running as fast as possible
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
working_set.add_decl(cmd);
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 nu_cmd_base::formats::to::delimited::merge_descriptors;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
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 bytes;
mod conversions;
mod filters;
mod formats;
mod platform;
mod strings;
pub use bytes::Bytes;
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
bind_command! {
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"
roxmltree = "0.18"
rusqlite = { version = "0.29", features = ["bundled"], optional = true }
rust-embed = "6.7"
same-file = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
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 std::collections::VecDeque;
use std::error::Error;
@ -142,24 +142,6 @@ pub fn find_non_record(values: &[Value]) -> Option<&Value> {
.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(
noheaders: bool,
sep: char,

View File

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

View File

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

View File

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

View File

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

View File

@ -1,16 +1,11 @@
mod base64;
mod decode;
mod decode_base64;
mod decode_hex;
mod encode;
mod encode_base64;
mod encode_hex;
mod encoding;
mod hex;
pub use self::decode::Decode;
pub use self::decode_base64::DecodeBase64;
pub use self::decode_hex::DecodeHex;
pub use self::encode::Encode;
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 detect_columns;
mod encode_decode;
mod format;
mod parse;
mod size;
mod split;
@ -10,7 +9,6 @@ mod str_;
pub use char_::Char;
pub use detect_columns::*;
pub use encode_decode::*;
pub use format::*;
pub use parse::*;
pub use size::Size;
pub use split::*;

View File

@ -52,6 +52,7 @@ fn each_uses_enumerate_index() {
}
#[test]
#[cfg(feature = "extra")]
fn each_while_uses_enumerate_index() {
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 flatten;
mod for_;
#[cfg(feature = "extra")]
mod format;
mod get;
mod glob;
@ -72,7 +73,9 @@ mod rename;
mod return_;
mod reverse;
mod rm;
#[cfg(feature = "extra")]
mod roll;
#[cfg(feature = "extra")]
mod rotate;
mod run_external;
mod save;

View File

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

View File

@ -54,7 +54,9 @@ fn in_and_if_else() -> TestResult {
#[test]
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]