diff --git a/.changeset/fix-formatter-empty-arrays.md b/.changeset/fix-formatter-empty-arrays.md new file mode 100644 index 00000000..b01488c2 --- /dev/null +++ b/.changeset/fix-formatter-empty-arrays.md @@ -0,0 +1 @@ +---\n"@googleworkspace/cli": patch\n---\n\nfix(formatter): correctly handle empty list responses from API diff --git a/src/formatter.rs b/src/formatter.rs index 08d4d287..dcbcb231 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -97,9 +97,7 @@ fn extract_items(value: &Value) -> Option<(&str, &Vec)> { continue; } if let Value::Array(arr) = val { - if !arr.is_empty() { - return Some((key, arr)); - } + return Some((key, arr)); } } } @@ -640,9 +638,9 @@ mod tests { #[test] fn test_format_table_empty_array() { let val = json!({"files": []}); - // No items to extract, falls back to single-object table + // Items are extracted correctly, but since the array is empty, we get (empty) let output = format_value(&val, &OutputFormat::Table); - assert!(output.contains("files")); + assert_eq!(output, "(empty)\n"); } #[test]