Skip to content

Add YAML output format support#42

Open
andrewshadura wants to merge 1 commit into
collabora:mainfrom
andrewshadura:yaml-output
Open

Add YAML output format support#42
andrewshadura wants to merge 1 commit into
collabora:mainfrom
andrewshadura:yaml-output

Conversation

@andrewshadura
Copy link
Copy Markdown
Contributor

YAML is useful as it’s slightly more compact and readable than JSON.

This requires the serde_yaml dependency.

Fixes: #40

YAML is useful as it’s slightly more compact and readable than JSON.

This requires the serde_yaml dependency.

Fixes: collabora#40

Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
@andrewshadura andrewshadura force-pushed the yaml-output branch 2 times, most recently from 7ad41b4 to 389b52c Compare February 17, 2026 12:59
@sjoerdsimons sjoerdsimons requested a review from Copilot March 6, 2026 10:46
@sjoerdsimons
Copy link
Copy Markdown
Contributor

serde_yaml is unmaintined so might not be the best optoin to introduce at this point

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds YAML as an additional structured output format for aptlyctl list-style commands, enabling more compact/readable exports alongside existing JSON support.

Changes:

  • Extend OutputFormat with a Yaml variant and wire it into snapshot/repo/publish listing outputs.
  • Add YAML support for repo packages list detailed results output.
  • Introduce the serde_yaml dependency (and update Cargo.lock accordingly).

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
aptlyctl/src/main.rs Adds Yaml to the CLI output format enum.
aptlyctl/src/snapshot.rs Enables YAML output for snapshot list.
aptlyctl/src/repo.rs Enables YAML output for repo list and repo packages list.
aptlyctl/src/publish.rs Enables YAML output for publish list.
aptlyctl/Cargo.toml Adds serde_yaml dependency.
Cargo.lock Locks serde_yaml and its transitive dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aptlyctl/src/repo.rs
}
OutputFormat::Yaml => {
serde_yaml::to_writer(&mut stdout(), &repos)?;
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The YAML output branch doesn’t emit a trailing newline, but the JSON branch does (via println!()). For consistent CLI UX (especially when piping / printing to a terminal), consider adding a newline after writing YAML as well.

Suggested change
}
println!();

Copilot uses AI. Check for mistakes.
Comment thread aptlyctl/src/publish.rs
println!();
}
OutputFormat::Yaml => {
serde_yaml::to_writer(&mut stdout(), &publishes)?;
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The YAML output branch writes the document but doesn’t add a trailing newline, whereas the JSON branch prints one. Consider adding a newline after YAML output to keep list output formatting consistent and avoid prompts appearing on the same line.

Suggested change
serde_yaml::to_writer(&mut stdout(), &publishes)?;
serde_yaml::to_writer(&mut stdout(), &publishes)?;
println!();

Copilot uses AI. Check for mistakes.
Comment thread aptlyctl/src/repo.rs
Comment on lines +72 to +84
OutputFormat::Yaml => {
let results = aptly
.repo(&args.repo)
.packages()
.query(args.query, false)
.detailed()
.await?;
if args.fail_if_empty && results.is_empty() {
return Ok(ExitCode::FAILURE);
}

serde_yaml::to_writer(&mut stdout(), &results)?;
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Json and Yaml branches both re-run the same detailed() query and the same empty-check, which is duplicated logic. Consider fetching results once and then serializing based on the selected structured output format to reduce duplication and make it harder for the two branches to drift over time.

Copilot uses AI. Check for mistakes.
Comment thread aptlyctl/Cargo.toml
color-eyre = "0.6.4"
http = "1.3.1"
serde_json = "1.0.140"
serde_yaml = "0.9"
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding serde_yaml = "0.9" currently resolves to serde_yaml 0.9.34+deprecated (see Cargo.lock) and brings in unsafe-libyaml (FFI/unsafe code). If YAML output is required, consider switching to a maintained alternative (e.g., serde_yaml_ng) or otherwise pinning/justifying the choice, since deprecated + FFI dependencies can have long-term maintenance and security implications.

Suggested change
serde_yaml = "0.9"
serde_yaml_ng = "0.10"

Copilot uses AI. Check for mistakes.
Comment thread aptlyctl/src/snapshot.rs
println!();
}
OutputFormat::Yaml => {
serde_yaml::to_writer(&mut stdout(), &snapshots)?;
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The YAML output branch doesn’t print a trailing newline, while the JSON branch prints one. This can lead to the next shell prompt appearing on the same line and is inconsistent with the JSON output for list. Consider printing a newline after writing YAML as well (or otherwise ensuring output ends with \n).

Suggested change
serde_yaml::to_writer(&mut stdout(), &snapshots)?;
serde_yaml::to_writer(&mut stdout(), &snapshots)?;
println!();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add YAML exports

3 participants