diff --git a/.cargo/config b/.cargo/config index e32687a32..a7b19c970 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,3 +1 @@ [build] - -#rustflags = ["--cfg", "data_processing_primitives"] diff --git a/Cargo.lock b/Cargo.lock index 2182a1daf..d0cc3ba7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2505,7 +2505,6 @@ dependencies = [ "byte-unit", "bytes 0.5.5", "calamine", - "cfg-if", "chrono", "clap", "clipboard", diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index dab3e5c83..6b8434854 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -29,7 +29,6 @@ bson = {version = "0.14.1", features = ["decimal128"]} byte-unit = "3.1.3" bytes = "0.5.5" calamine = "0.16" -cfg-if = "0.1" chrono = {version = "0.4.11", features = ["serde"]} clap = "2.33.1" codespan-reporting = "0.9.5" diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index 7406317ca..21e33da52 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -417,17 +417,6 @@ pub fn create_default_context( whole_stream_command(RandomUUID), ]); - cfg_if::cfg_if! { - if #[cfg(data_processing_primitives)] { - context.add_commands(vec![ - whole_stream_command(ReduceBy), - whole_stream_command(EvaluateBy), - whole_stream_command(TSortBy), - whole_stream_command(MapMaxBy), - ]); - } - } - #[cfg(feature = "clipboard")] { context.add_commands(vec![whole_stream_command(crate::commands::clip::Clip)]); diff --git a/crates/nu-cli/src/commands.rs b/crates/nu-cli/src/commands.rs index 05bca9b10..97436598d 100644 --- a/crates/nu-cli/src/commands.rs +++ b/crates/nu-cli/src/commands.rs @@ -35,8 +35,6 @@ pub(crate) mod du; pub(crate) mod each; pub(crate) mod echo; pub(crate) mod enter; -#[allow(unused)] -pub(crate) mod evaluate_by; pub(crate) mod every; pub(crate) mod exit; pub(crate) mod first; @@ -74,8 +72,6 @@ pub(crate) mod keep_while; pub(crate) mod last; pub(crate) mod lines; pub(crate) mod ls; -#[allow(unused)] -pub(crate) mod map_max_by; pub(crate) mod math; pub(crate) mod merge; pub(crate) mod mkdir; @@ -91,8 +87,6 @@ pub(crate) mod prev; pub(crate) mod pwd; pub(crate) mod random; pub(crate) mod range; -#[allow(unused)] -pub(crate) mod reduce_by; pub(crate) mod reject; pub(crate) mod rename; pub(crate) mod reverse; @@ -109,8 +103,6 @@ pub(crate) mod sort_by; pub(crate) mod split; pub(crate) mod split_by; pub(crate) mod str_; -#[allow(unused)] -pub(crate) mod t_sort_by; pub(crate) mod table; pub(crate) mod tags; pub(crate) mod to; @@ -173,8 +165,6 @@ pub(crate) mod clear; pub(crate) use clear::Clear; pub(crate) mod touch; pub(crate) use enter::Enter; -#[allow(unused_imports)] -pub(crate) use evaluate_by::EvaluateBy; pub(crate) use every::Every; pub(crate) use exit::Exit; pub(crate) use first::First; @@ -212,8 +202,6 @@ pub(crate) use keep_while::KeepWhile; pub(crate) use last::Last; pub(crate) use lines::Lines; pub(crate) use ls::Ls; -#[allow(unused_imports)] -pub(crate) use map_max_by::MapMaxBy; pub(crate) use math::{ Math, MathAverage, MathMaximum, MathMedian, MathMinimum, MathMode, MathStddev, MathSummation, MathVariance, @@ -231,8 +219,6 @@ pub(crate) use prev::Previous; pub(crate) use pwd::Pwd; pub(crate) use random::{Random, RandomBool, RandomDice, RandomUUID}; pub(crate) use range::Range; -#[allow(unused_imports)] -pub(crate) use reduce_by::ReduceBy; pub(crate) use reject::Reject; pub(crate) use rename::Rename; pub(crate) use reverse::Reverse; @@ -251,8 +237,6 @@ pub(crate) use str_::{ Str, StrCapitalize, StrCollect, StrDowncase, StrFindReplace, StrFrom, StrLength, StrReverse, StrSet, StrSubstring, StrToDatetime, StrToDecimal, StrToInteger, StrTrim, StrUpcase, }; -#[allow(unused_imports)] -pub(crate) use t_sort_by::TSortBy; pub(crate) use table::Table; pub(crate) use tags::Tags; pub(crate) use to::To; diff --git a/crates/nu-cli/src/commands/evaluate_by.rs b/crates/nu-cli/src/commands/evaluate_by.rs deleted file mode 100644 index 6db406724..000000000 --- a/crates/nu-cli/src/commands/evaluate_by.rs +++ /dev/null @@ -1,83 +0,0 @@ -use crate::commands::WholeStreamCommand; -use crate::prelude::*; -use crate::utils::data_processing::{evaluate, fetch}; -use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value}; -use nu_source::{SpannedItem, Tagged}; -use nu_value_ext::ValueExt; - -pub struct EvaluateBy; - -#[derive(Deserialize)] -pub struct EvaluateByArgs { - evaluate_with: Option>, -} - -#[async_trait] -impl WholeStreamCommand for EvaluateBy { - fn name(&self) -> &str { - "evaluate-by" - } - - fn signature(&self) -> Signature { - Signature::build("evaluate-by").named( - "evaluate_with", - SyntaxShape::String, - "the name of the column to evaluate by", - Some('w'), - ) - } - - fn usage(&self) -> &str { - "Creates a new table with the data from the tables rows evaluated by the column given." - } - - async fn run( - &self, - args: CommandArgs, - registry: &CommandRegistry, - ) -> Result { - evaluate_by(args, registry).await - } -} - -pub async fn evaluate_by( - args: CommandArgs, - registry: &CommandRegistry, -) -> Result { - let registry = registry.clone(); - let name = args.call_info.name_tag.clone(); - let (EvaluateByArgs { evaluate_with }, mut input) = args.process(®istry).await?; - let values: Vec = input.collect().await; - - if values.is_empty() { - Err(ShellError::labeled_error( - "Expected table from pipeline", - "requires a table input", - name, - )) - } else { - let evaluate_with = if let Some(evaluator) = evaluate_with { - Some(evaluator.item().clone()) - } else { - None - }; - - match evaluate(&values[0], evaluate_with, name) { - Ok(evaluated) => Ok(OutputStream::one(ReturnSuccess::value(evaluated))), - Err(err) => Err(err), - } - } -} - -#[cfg(test)] -mod tests { - use super::EvaluateBy; - - #[test] - fn examples_work_as_expected() { - use crate::examples::test as test_examples; - - test_examples(EvaluateBy {}) - } -} diff --git a/crates/nu-cli/src/commands/map_max_by.rs b/crates/nu-cli/src/commands/map_max_by.rs deleted file mode 100644 index a8664ab72..000000000 --- a/crates/nu-cli/src/commands/map_max_by.rs +++ /dev/null @@ -1,84 +0,0 @@ -use crate::commands::WholeStreamCommand; -use crate::data::value; -use crate::prelude::*; -use crate::utils::data_processing::map_max; -use nu_errors::ShellError; -use nu_protocol::{Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value}; -use nu_source::Tagged; -use num_traits::cast::ToPrimitive; - -pub struct MapMaxBy; - -#[derive(Deserialize)] -pub struct MapMaxByArgs { - column_name: Option>, -} - -#[async_trait] -impl WholeStreamCommand for MapMaxBy { - fn name(&self) -> &str { - "map-max-by" - } - - fn signature(&self) -> Signature { - Signature::build("map-max-by").named( - "column_name", - SyntaxShape::String, - "the name of the column to map-max the table's rows", - Some('c'), - ) - } - - fn usage(&self) -> &str { - "Creates a new table with the data from the tables rows maxed by the column given." - } - - async fn run( - &self, - args: CommandArgs, - registry: &CommandRegistry, - ) -> Result { - map_max_by(args, registry).await - } -} - -pub async fn map_max_by( - args: CommandArgs, - registry: &CommandRegistry, -) -> Result { - let registry = registry.clone(); - let name = args.call_info.name_tag.clone(); - let (MapMaxByArgs { column_name }, mut input) = args.process(®istry).await?; - let values: Vec = input.collect().await; - - if values.is_empty() { - Err(ShellError::labeled_error( - "Expected table from pipeline", - "requires a table input", - name, - )) - } else { - let map_by_column = if let Some(column_to_map) = column_name { - Some(column_to_map.item().clone()) - } else { - None - }; - - match map_max(&values[0], map_by_column, name) { - Ok(table_maxed) => Ok(OutputStream::one(ReturnSuccess::value(table_maxed))), - Err(err) => Err(err), - } - } -} - -#[cfg(test)] -mod tests { - use super::MapMaxBy; - - #[test] - fn examples_work_as_expected() { - use crate::examples::test as test_examples; - - test_examples(MapMaxBy {}) - } -} diff --git a/crates/nu-cli/src/commands/reduce_by.rs b/crates/nu-cli/src/commands/reduce_by.rs deleted file mode 100644 index 404b7adbb..000000000 --- a/crates/nu-cli/src/commands/reduce_by.rs +++ /dev/null @@ -1,83 +0,0 @@ -use crate::commands::WholeStreamCommand; -use crate::prelude::*; -use crate::utils::data_processing::reduce; -use nu_errors::ShellError; -use nu_protocol::{Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value}; -use nu_source::Tagged; -use num_traits::cast::ToPrimitive; - -pub struct ReduceBy; - -#[derive(Deserialize)] -pub struct ReduceByArgs { - reduce_with: Option>, -} - -#[async_trait] -impl WholeStreamCommand for ReduceBy { - fn name(&self) -> &str { - "reduce-by" - } - - fn signature(&self) -> Signature { - Signature::build("reduce-by").named( - "reduce_with", - SyntaxShape::String, - "the command to reduce by with", - Some('w'), - ) - } - - fn usage(&self) -> &str { - "Creates a new table with the data from the tables rows reduced by the command given." - } - - async fn run( - &self, - args: CommandArgs, - registry: &CommandRegistry, - ) -> Result { - reduce_by(args, registry).await - } -} - -pub async fn reduce_by( - args: CommandArgs, - registry: &CommandRegistry, -) -> Result { - let registry = registry.clone(); - let name = args.call_info.name_tag.clone(); - let (ReduceByArgs { reduce_with }, mut input) = args.process(®istry).await?; - let values: Vec = input.collect().await; - - if values.is_empty() { - return Err(ShellError::labeled_error( - "Expected table from pipeline", - "requires a table input", - name, - )); - } - - let reduce_with = if let Some(reducer) = reduce_with { - Some(reducer.item().clone()) - } else { - None - }; - - match reduce(&values[0], reduce_with, name) { - Ok(reduced) => Ok(OutputStream::one(ReturnSuccess::value(reduced))), - Err(err) => Err(err), - } -} - -#[cfg(test)] -mod tests { - use super::ReduceBy; - - #[test] - fn examples_work_as_expected() { - use crate::examples::test as test_examples; - - test_examples(ReduceBy {}) - } -} diff --git a/crates/nu-cli/src/commands/t_sort_by.rs b/crates/nu-cli/src/commands/t_sort_by.rs deleted file mode 100644 index a1aac2e91..000000000 --- a/crates/nu-cli/src/commands/t_sort_by.rs +++ /dev/null @@ -1,113 +0,0 @@ -use crate::commands::WholeStreamCommand; -use crate::data::TaggedListBuilder; -use crate::prelude::*; -use crate::utils::data_processing::{columns_sorted, t_sort}; -use chrono::{DateTime, NaiveDate, Utc}; -use nu_errors::ShellError; -use nu_protocol::{ - Primitive, ReturnSuccess, Signature, SyntaxShape, TaggedDictBuilder, UntaggedValue, Value, -}; -use nu_source::Tagged; -use nu_value_ext::get_data_by_key; - -pub struct TSortBy; - -#[derive(Deserialize)] -pub struct TSortByArgs { - #[serde(rename(deserialize = "show-columns"))] - show_columns: bool, - group_by: Option>, - #[allow(unused)] - split_by: Option, -} - -#[async_trait] -impl WholeStreamCommand for TSortBy { - fn name(&self) -> &str { - "t-sort-by" - } - - fn signature(&self) -> Signature { - Signature::build("t-sort-by") - .switch( - "show-columns", - "Displays the column names sorted", - Some('c'), - ) - .named( - "group_by", - SyntaxShape::String, - "the name of the column to group by", - Some('g'), - ) - .named( - "split_by", - SyntaxShape::String, - "the name of the column within the grouped by table to split by", - Some('s'), - ) - } - - fn usage(&self) -> &str { - "Sort by the given columns." - } - - async fn run( - &self, - args: CommandArgs, - registry: &CommandRegistry, - ) -> Result { - t_sort_by(args, registry).await - } -} - -async fn t_sort_by( - args: CommandArgs, - registry: &CommandRegistry, -) -> Result { - let registry = registry.clone(); - let name = args.call_info.name_tag.clone(); - let ( - TSortByArgs { - show_columns, - group_by, - .. - }, - mut input, - ) = args.process(®istry).await?; - let values: Vec = input.collect().await; - - let column_grouped_by_name = if let Some(grouped_by) = group_by { - Some(grouped_by) - } else { - None - }; - - if show_columns { - Ok(futures::stream::iter( - columns_sorted(column_grouped_by_name, &values[0], &name) - .into_iter() - .map(move |label| { - ReturnSuccess::value(UntaggedValue::string(label.item).into_value(label.tag)) - }), - ) - .to_output_stream()) - } else { - match t_sort(column_grouped_by_name, None, &values[0], name) { - Ok(sorted) => Ok(OutputStream::one(ReturnSuccess::value(sorted))), - Err(err) => Ok(OutputStream::one(Err(err))), - } - } -} - -#[cfg(test)] -mod tests { - use super::TSortBy; - - #[test] - fn examples_work_as_expected() { - use crate::examples::test as test_examples; - - test_examples(TSortBy {}) - } -} diff --git a/crates/nu-cli/src/data/base.rs b/crates/nu-cli/src/data/base.rs index 8bef57d6c..318218c66 100644 --- a/crates/nu-cli/src/data/base.rs +++ b/crates/nu-cli/src/data/base.rs @@ -49,7 +49,6 @@ impl std::convert::TryFrom> for Switch { } } -#[allow(unused)] pub(crate) fn select_fields(obj: &Value, fields: &[String], tag: impl Into) -> Value { let mut out = TaggedDictBuilder::new(tag); diff --git a/crates/nu-cli/src/shell/filesystem_shell.rs b/crates/nu-cli/src/shell/filesystem_shell.rs index 32f7b5f19..cdfc62723 100644 --- a/crates/nu-cli/src/shell/filesystem_shell.rs +++ b/crates/nu-cli/src/shell/filesystem_shell.rs @@ -822,24 +822,26 @@ fn is_empty_dir(dir: impl AsRef) -> bool { } fn is_hidden_dir(dir: impl AsRef) -> bool { - cfg_if::cfg_if! { - if #[cfg(windows)] { - use std::os::windows::fs::MetadataExt; + #[cfg(windows)] + { + use std::os::windows::fs::MetadataExt; - if let Ok(metadata) = dir.as_ref().metadata() { - let attributes = metadata.file_attributes(); - // https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants - (attributes & 0x2) != 0 - } else { - false - } + if let Ok(metadata) = dir.as_ref().metadata() { + let attributes = metadata.file_attributes(); + // https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants + (attributes & 0x2) != 0 } else { - dir.as_ref() - .file_name() - .map(|name| name.to_string_lossy().starts_with('.')) - .unwrap_or(false) + false } } + + #[cfg(not(windows))] + { + dir.as_ref() + .file_name() + .map(|name| name.to_string_lossy().starts_with('.')) + .unwrap_or(false) + } } fn requote(