compose: Make --print-only happen earlier and be quiet

Don't print the version or other warnings; ensure we output clean JSON.

Prep for fixing https://github.com/coreos/fedora-coreos-config/pull/24
(This helps, but we still need to expand `${basearch}`)

Closes: #1648
Approved by: jlebon
This commit is contained in:
Colin Walters 2018-10-30 14:19:49 +00:00 committed by Atomic Bot
parent 87441d9ec2
commit 5b8b37658f
2 changed files with 12 additions and 14 deletions

View File

@ -591,9 +591,15 @@ impl_install_tree (RpmOstreeTreeComposeContext *self,
GCancellable *cancellable,
GError **error)
{
if (opt_print_only)
{
g_print ("%s\n", ror_treefile_get_json_string (self->treefile_rs));
return TRUE; /* Note early return */
}
/* Print version number */
g_printerr ("RPM-OSTree Version: %s\n", PACKAGE_VERSION);
if (getuid () != 0)
{
if (!opt_unified_core)
@ -618,19 +624,6 @@ impl_install_tree (RpmOstreeTreeComposeContext *self,
*/
*out_changed = FALSE;
if (opt_print_only)
{
glnx_unref_object JsonGenerator *generator = json_generator_new ();
g_autoptr(GOutputStream) stdout = g_unix_output_stream_new (1, FALSE);
json_generator_set_pretty (generator, TRUE);
json_generator_set_root (generator, self->treefile_rootval);
(void) json_generator_to_stream (generator, stdout, NULL, NULL);
/* Note early return */
return TRUE;
}
/* Read the previous commit */
if (self->ref)
{

View File

@ -6,6 +6,11 @@ dn=$(cd $(dirname $0) && pwd)
. ${dn}/libcomposetest.sh
prepare_compose_test "basic-unified"
# Test --print-only, currently requires --repo
rpm-ostree compose tree --repo=${repobuild} --print-only ${treefile} > treefile.json
# Verify it's valid JSON
jq -r .ref < treefile.json > ref.txt
assert_file_has_content_literal ref.txt "${treeref}"
# Test metadata json with objects, arrays, numbers
cat > metadata.json <<EOF
{