Revert PRs for 0.99.1 patch (#14119)

# Description

Temporarily reverts PRs merged after the 0.99.1 bump.
This commit is contained in:
Ian Manske
2024-10-17 19:51:14 -07:00
committed by GitHub
parent e735bd475f
commit 28b6db115a
33 changed files with 287 additions and 782 deletions

View File

@ -18,7 +18,7 @@ impl Command for IntoValue {
.input_output_types(vec![(Type::table(), Type::table())])
.named(
"columns",
SyntaxShape::List(Box::new(SyntaxShape::Any)),
SyntaxShape::Table(vec![]),
"list of columns to update",
Some('c'),
)

View File

@ -101,7 +101,7 @@ fn all_columns(span: Span) -> Value {
let environment = {
let mut env_rec = Record::new();
for val in p.environ() {
if let Some((key, value)) = val.to_string_lossy().split_once('=') {
if let Some((key, value)) = val.split_once('=') {
let is_env_var_a_list = {
{
#[cfg(target_family = "windows")]
@ -146,8 +146,8 @@ fn all_columns(span: Span) -> Value {
"root" => root,
"cwd" => cwd,
"exe_path" => exe_path,
"command" => Value::string(p.cmd().join(std::ffi::OsStr::new(" ")).to_string_lossy(), span),
"name" => Value::string(p.name().to_string_lossy(), span),
"command" => Value::string(p.cmd().join(" "), span),
"name" => Value::string(p.name(), span),
"environment" => environment,
},
span,

View File

@ -38,14 +38,6 @@ impl Command for GroupBy {
"Splits a list or table into groups, and returns a record containing those groups."
}
fn extra_description(&self) -> &str {
r#"the group-by command makes some assumptions:
- if the input data is not a string, the grouper will convert the key to string but the values will remain in their original format. e.g. with bools, "true" and true would be in the same group (see example).
- datetime is formatted based on your configuration setting. use `format date` to change the format.
- filesize is formatted based on your configuration setting. use `format filesize` to change the format.
- some nushell values are not supported, such as closures."#
}
fn run(
&self,
engine_state: &EngineState,
@ -122,20 +114,6 @@ impl Command for GroupBy {
}),
])),
},
Example {
description: "Group bools, whether they are strings or actual bools",
example: r#"[true "true" false "false"] | group-by"#,
result: Some(Value::test_record(record! {
"true" => Value::test_list(vec![
Value::test_bool(true),
Value::test_string("true"),
]),
"false" => Value::test_list(vec![
Value::test_bool(false),
Value::test_string("false"),
]),
})),
}
]
}
}
@ -149,7 +127,6 @@ pub fn group_by(
let head = call.head;
let grouper: Option<Value> = call.opt(engine_state, stack, 0)?;
let to_table = call.has_flag(engine_state, stack, "to-table")?;
let config = engine_state.get_config();
let values: Vec<Value> = input.into_iter().collect();
if values.is_empty() {
@ -160,7 +137,7 @@ pub fn group_by(
Some(grouper) => {
let span = grouper.span();
match grouper {
Value::CellPath { val, .. } => group_cell_path(val, values, config)?,
Value::CellPath { val, .. } => group_cell_path(val, values)?,
Value::Closure { val, .. } => {
group_closure(values, span, *val, engine_state, stack)?
}
@ -172,7 +149,7 @@ pub fn group_by(
}
}
}
None => group_no_grouper(values, config)?,
None => group_no_grouper(values)?,
};
let value = if to_table {
@ -187,7 +164,6 @@ pub fn group_by(
fn group_cell_path(
column_name: CellPath,
values: Vec<Value>,
config: &nu_protocol::Config,
) -> Result<IndexMap<String, Vec<Value>>, ShellError> {
let mut groups = IndexMap::<_, Vec<_>>::new();
@ -200,21 +176,18 @@ fn group_cell_path(
continue; // likely the result of a failed optional access, ignore this value
}
let key = key.to_abbreviated_string(config);
let key = key.coerce_string()?;
groups.entry(key).or_default().push(value);
}
Ok(groups)
}
fn group_no_grouper(
values: Vec<Value>,
config: &nu_protocol::Config,
) -> Result<IndexMap<String, Vec<Value>>, ShellError> {
fn group_no_grouper(values: Vec<Value>) -> Result<IndexMap<String, Vec<Value>>, ShellError> {
let mut groups = IndexMap::<_, Vec<_>>::new();
for value in values.into_iter() {
let key = value.to_abbreviated_string(config);
let key = value.coerce_string()?;
groups.entry(key).or_default().push(value);
}
@ -230,13 +203,12 @@ fn group_closure(
) -> Result<IndexMap<String, Vec<Value>>, ShellError> {
let mut groups = IndexMap::<_, Vec<_>>::new();
let mut closure = ClosureEval::new(engine_state, stack, closure);
let config = engine_state.get_config();
for value in values {
let key = closure
.run_with_value(value.clone())?
.into_value(span)?
.to_abbreviated_string(config);
.coerce_into_string()?;
groups.entry(key).or_default().push(value);
}

View File

@ -84,16 +84,16 @@ pub fn split_by(
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let name = call.head;
let config = engine_state.get_config();
let splitter: Option<Value> = call.opt(engine_state, stack, 0)?;
match splitter {
Some(v) => {
let splitter = Some(Spanned {
item: v.to_abbreviated_string(config),
item: v.coerce_into_string()?,
span: name,
});
Ok(split(splitter.as_ref(), input, name, config)?)
Ok(split(splitter.as_ref(), input, name)?)
}
// This uses the same format as the 'requires a column name' error in sort_utils.rs
None => Err(ShellError::GenericError {
@ -110,7 +110,6 @@ pub fn split(
column_name: Option<&Spanned<String>>,
values: PipelineData,
span: Span,
config: &nu_protocol::Config,
) -> Result<PipelineData, ShellError> {
let grouper = if let Some(column_name) = column_name {
Grouper::ByColumn(Some(column_name.clone()))
@ -128,7 +127,7 @@ pub fn split(
};
match group_key {
Some(group_key) => Ok(group_key.to_abbreviated_string(config)),
Some(group_key) => Ok(group_key.coerce_string()?),
None => Err(ShellError::CantFindColumn {
col_name: column_name.item.to_string(),
span: Some(column_name.span),
@ -137,12 +136,12 @@ pub fn split(
}
};
data_split(values, Some(&block), span, config)
data_split(values, Some(&block), span)
}
Grouper::ByColumn(None) => {
let block = move |_, row: &Value| Ok(row.to_abbreviated_string(config));
let block = move |_, row: &Value| row.coerce_string();
data_split(values, Some(&block), span, config)
data_split(values, Some(&block), span)
}
}
}
@ -152,7 +151,6 @@ fn data_group(
values: &Value,
grouper: Option<&dyn Fn(usize, &Value) -> Result<String, ShellError>>,
span: Span,
config: &nu_protocol::Config,
) -> Result<Value, ShellError> {
let mut groups: IndexMap<String, Vec<Value>> = IndexMap::new();
@ -160,7 +158,7 @@ fn data_group(
let group_key = if let Some(ref grouper) = grouper {
grouper(idx, &value)
} else {
Ok(value.to_abbreviated_string(config))
value.coerce_string()
};
let group = groups.entry(group_key?).or_default();
@ -181,7 +179,6 @@ pub fn data_split(
value: PipelineData,
splitter: Option<&dyn Fn(usize, &Value) -> Result<String, ShellError>>,
dst_span: Span,
config: &nu_protocol::Config,
) -> Result<PipelineData, ShellError> {
let mut splits = indexmap::IndexMap::new();
@ -191,7 +188,7 @@ pub fn data_split(
match v {
Value::Record { val: grouped, .. } => {
for (outer_key, list) in grouped.into_owned() {
match data_group(&list, splitter, span, config) {
match data_group(&list, splitter, span) {
Ok(grouped_vals) => {
if let Value::Record { val: sub, .. } = grouped_vals {
for (inner_key, subset) in sub.into_owned() {

View File

@ -46,7 +46,7 @@ impl Command for Uniq {
}
fn search_terms(&self) -> Vec<&str> {
vec!["distinct", "deduplicate", "count"]
vec!["distinct", "deduplicate"]
}
fn run(