mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 05:24:56 +02:00
Fix column count to not break on empty tables (#2374)
This commit is contained in:
@ -39,23 +39,26 @@ impl WholeStreamCommand for Count {
|
||||
let (CountArgs { column }, input) = args.process(®istry).await?;
|
||||
let rows: Vec<Value> = input.collect().await;
|
||||
|
||||
if column {
|
||||
if let UntaggedValue::Row(dict) = &rows[0].value {
|
||||
return Ok(OutputStream::one(
|
||||
UntaggedValue::int(dict.length()).into_value(tag),
|
||||
));
|
||||
let count = if column {
|
||||
if rows.is_empty() {
|
||||
0
|
||||
} else {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Cannot obtain column count",
|
||||
"cannot obtain column count",
|
||||
tag,
|
||||
));
|
||||
match &rows[0].value {
|
||||
UntaggedValue::Row(dictionary) => dictionary.length(),
|
||||
_ => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Cannot obtain column count",
|
||||
"cannot obtain column count",
|
||||
tag,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rows.len()
|
||||
};
|
||||
|
||||
Ok(OutputStream::one(
|
||||
UntaggedValue::int(rows.len()).into_value(tag),
|
||||
))
|
||||
Ok(OutputStream::one(UntaggedValue::int(count).into_value(tag)))
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
Reference in New Issue
Block a user