Emit JSON output with `--quiet` (#14810)

This commit is contained in:
Zanie Blue 2025-07-22 08:21:54 -05:00 committed by GitHub
parent 2677e85df9
commit e49d61db1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 2 deletions

View File

@ -273,7 +273,7 @@ pub(crate) async fn sync(
dry_run: dry_run.enabled(),
};
if let Some(output) = report.format(output_format) {
writeln!(printer.stdout(), "{output}")?;
writeln!(printer.stdout_important(), "{output}")?;
}
return Ok(ExitStatus::Success);
}
@ -363,7 +363,7 @@ pub(crate) async fn sync(
};
if let Some(output) = report.format(output_format) {
writeln!(printer.stdout(), "{output}")?;
writeln!(printer.stdout_important(), "{output}")?;
}
// Identify the installation target.

View File

@ -432,6 +432,46 @@ fn sync_json() -> Result<()> {
The lockfile at `uv.lock` needs to be updated, but `--locked` was provided. To update the lockfile, run `uv lock`.
");
// Test that JSON output is shown even with --quiet flag
uv_snapshot!(context.filters(), context.sync()
.arg("--quiet")
.arg("--frozen")
.arg("--output-format").arg("json"), @r#"
success: true
exit_code: 0
----- stdout -----
{
"schema": {
"version": "preview"
},
"target": "project",
"project": {
"path": "[TEMP_DIR]/",
"workspace": {
"path": "[TEMP_DIR]/"
}
},
"sync": {
"environment": {
"path": "[VENV]/",
"python": {
"path": "[VENV]/[BIN]/[PYTHON]",
"version": "3.12.[X]",
"implementation": "cpython"
}
},
"action": "check"
},
"lock": {
"path": "[TEMP_DIR]/uv.lock",
"action": "use"
},
"dry_run": false
}
----- stderr -----
"#);
Ok(())
}