Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
809 changes: 437 additions & 372 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/nu-cmd-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
1 change: 1 addition & 0 deletions crates/nu-cmd-base/src/formats/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod to;
20 changes: 20 additions & 0 deletions crates/nu-cmd-base/src/formats/to/delimited.rs
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions crates/nu-cmd-base/src/formats/to/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod delimited;
1 change: 1 addition & 0 deletions crates/nu-cmd-base/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod formats;
pub mod input_handler;
pub mod util;
10 changes: 10 additions & 0 deletions crates/nu-cmd-extra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,21 @@ 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"]
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" }
3 changes: 3 additions & 0 deletions crates/nu-cmd-extra/src/example_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions crates/nu-cmd-extra/src/extra/conversions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod fmt;

pub(crate) use fmt::Fmt;
9 changes: 9 additions & 0 deletions crates/nu-cmd-extra/src/extra/filters/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions crates/nu-cmd-extra/src/extra/formats/from/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod url;
5 changes: 5 additions & 0 deletions crates/nu-cmd-extra/src/extra/formats/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod from;
mod to;

pub(crate) use from::url::FromUrl;
pub(crate) use to::html::ToHtml;
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
1 change: 1 addition & 0 deletions crates/nu-cmd-extra/src/extra/formats/to/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod html;
28 changes: 28 additions & 0 deletions crates/nu-cmd-extra/src/extra/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions crates/nu-cmd-extra/src/extra/platform/ansi/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod gradient;
mod link;

pub(crate) use gradient::SubCommand as Gradient;
pub(crate) use link::SubCommand as Link;
1 change: 1 addition & 0 deletions crates/nu-cmd-extra/src/extra/platform/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod ansi;
6 changes: 6 additions & 0 deletions crates/nu-cmd-extra/src/extra/strings/encode_decode/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod decode_hex;
mod encode_hex;
mod hex;

pub(crate) use decode_hex::DecodeHex;
pub(crate) use encode_hex::EncodeHex;
5 changes: 5 additions & 0 deletions crates/nu-cmd-extra/src/extra/strings/format/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod command;
mod filesize;

pub(crate) use command::Format;
pub(crate) use filesize::FileSize;
2 changes: 2 additions & 0 deletions crates/nu-cmd-extra/src/extra/strings/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub(crate) mod encode_decode;
pub(crate) mod format;
1 change: 0 additions & 1 deletion crates/nu-command/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions crates/nu-command/src/conversions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod fill;
mod fmt;
pub(crate) mod into;

pub use fill::Fill;
pub use fmt::Fmt;
pub use into::*;
17 changes: 0 additions & 17 deletions crates/nu-command/src/default_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
DropColumn,
DropNth,
Each,
EachWhile,
Empty,
Enumerate,
Every,
Expand Down Expand Up @@ -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,
Expand All @@ -91,7 +84,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
UniqBy,
Upsert,
Update,
UpdateCells,
Values,
Where,
Window,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -301,7 +285,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
// Conversions
bind_command! {
Fill,
Fmt,
Into,
IntoBool,
IntoBinary,
Expand Down
8 changes: 0 additions & 8 deletions crates/nu-command/src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod compact;
mod default;
mod drop;
mod each;
mod each_while;
mod empty;
mod enumerate;
mod every;
Expand All @@ -33,8 +32,6 @@ mod reduce;
mod reject;
mod rename;
mod reverse;
mod roll;
mod rotate;
mod select;
mod shuffle;
mod skip;
Expand All @@ -46,7 +43,6 @@ mod transpose;
mod uniq;
mod uniq_by;
mod update;
mod update_cells;
mod upsert;
mod utils;
mod values;
Expand All @@ -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;
Expand All @@ -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::*;
Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions crates/nu-command/src/formats/from/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 1 addition & 19 deletions crates/nu-command/src/formats/to/delimited.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/formats/to/md.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
2 changes: 0 additions & 2 deletions crates/nu-command/src/formats/to/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod command;
mod csv;
mod delimited;
mod html;
mod json;
mod md;
mod nuon;
Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions crates/nu-command/src/platform/ansi/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion crates/nu-command/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down