Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-yaml-pagination-separators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gws": patch
---

fix: add YAML document separators (---) when paginating with --page-all --format yaml
23 changes: 15 additions & 8 deletions src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ pub fn format_value(value: &Value, format: &OutputFormat) -> String {
/// contains only data rows, making the combined output machine-parseable.
///
/// For JSON the output is compact (one JSON object per line / NDJSON).
/// For YAML the page separator is preserved as-is.
/// For YAML each page is prefixed with a `---` document separator so the
/// combined stream is a valid YAML multi-document file.
pub fn format_value_paginated(value: &Value, format: &OutputFormat, is_first_page: bool) -> String {
match format {
OutputFormat::Json => serde_json::to_string(value).unwrap_or_default(),
OutputFormat::Csv => format_csv_page(value, is_first_page),
OutputFormat::Table => format_table_page(value, is_first_page),
OutputFormat::Yaml => format_yaml(value),
// Prefix every page with a YAML document separator so that the
// concatenated stream is parseable as a multi-document YAML file.
OutputFormat::Yaml => format!("---\n{}", format_yaml(value)),
}
}

Expand Down Expand Up @@ -560,13 +563,17 @@ mod tests {
}

#[test]
fn test_format_value_paginated_json_is_compact() {
let val = json!({"files": [{"id": "1"}]});
let output = format_value_paginated(&val, &OutputFormat::Json, true);
// Compact JSON — no pretty-printed newlines inside the object
fn test_format_value_paginated_yaml_has_document_separator() {
let val = json!({"files": [{"id": "1", "name": "foo"}]});
let first = format_value_paginated(&val, &OutputFormat::Yaml, true);
let second = format_value_paginated(&val, &OutputFormat::Yaml, false);
assert!(
first.starts_with("---\n"),
"first YAML page must start with ---"
);
assert!(
!output.contains("\n "),
"JSON must be compact in paginated mode"
second.starts_with("---\n"),
"continuation YAML pages must also start with ---"
);
}
}
Loading