@@ -10,10 +10,11 @@ use camino::{Utf8Path, Utf8PathBuf};
1010use cap_std:: fs:: Dir ;
1111use cap_std_ext:: cap_std;
1212use cap_std_ext:: prelude:: CapStdExtDirExt ;
13- use clap:: { Parser , Subcommand } ;
13+ use clap:: { builder :: ArgPredicate , Parser , Subcommand } ;
1414use fn_error_context:: context;
1515use io_lifetimes:: AsFd ;
1616use ostree:: { gio, glib} ;
17+ use serde_json;
1718use std:: borrow:: Cow ;
1819use std:: collections:: BTreeMap ;
1920use std:: ffi:: OsString ;
@@ -178,6 +179,10 @@ pub(crate) enum ContainerOpts {
178179 /// Image reference, e.g. ostree-remote-image:someremote:registry:quay.io/exampleos/exampleos:latest
179180 #[ clap( value_parser = parse_imgref) ]
180181 imgref_new : OstreeImageReference ,
182+
183+ /// Use JSON as output format.
184+ #[ clap( long) ]
185+ json : bool ,
181186 } ,
182187}
183188
@@ -234,6 +239,10 @@ pub(crate) enum ContainerImageOpts {
234239 /// the new manifest.
235240 #[ clap( long) ]
236241 check : Option < Utf8PathBuf > ,
242+
243+ /// Use JSON as output format. Only applies to the --check option.
244+ #[ clap( long, requires_if( ArgPredicate :: IsPresent , "check" ) ) ]
245+ json : bool ,
237246 } ,
238247
239248 /// Output metadata about an already stored container image.
@@ -717,6 +726,7 @@ async fn container_store(
717726 proxyopts : ContainerProxyOpts ,
718727 quiet : bool ,
719728 check : Option < Utf8PathBuf > ,
729+ json : bool ,
720730) -> Result < ( ) > {
721731 let mut imp = ImageImporter :: new ( repo, imgref, proxyopts. into ( ) ) . await ?;
722732 let prep = match imp. prepare ( ) . await ? {
@@ -739,7 +749,11 @@ async fn container_store(
739749 }
740750 if let Some ( previous_state) = prep. previous_state . as_ref ( ) {
741751 let diff = ManifestDiff :: new ( & previous_state. manifest , & prep. manifest ) ;
742- diff. print ( ) ;
752+ if json {
753+ println ! ( "{:#?}" , serde_json:: to_string( & diff) ) ;
754+ } else {
755+ diff. print ( ) ;
756+ }
743757 }
744758 print_layer_status ( & prep) ;
745759 let printer = ( !quiet) . then ( || {
@@ -965,9 +979,10 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
965979 proxyopts,
966980 quiet,
967981 check,
982+ json,
968983 } => {
969984 let repo = parse_repo ( & repo) ?;
970- container_store ( & repo, & imgref, proxyopts, quiet, check) . await
985+ container_store ( & repo, & imgref, proxyopts, quiet, check, json ) . await
971986 }
972987 ContainerImageOpts :: History { repo, imgref } => {
973988 let repo = parse_repo ( & repo) ?;
@@ -1177,12 +1192,17 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
11771192 ContainerOpts :: Compare {
11781193 imgref_old,
11791194 imgref_new,
1195+ json,
11801196 } => {
11811197 let ( manifest_old, _) = crate :: container:: fetch_manifest ( & imgref_old) . await ?;
11821198 let ( manifest_new, _) = crate :: container:: fetch_manifest ( & imgref_new) . await ?;
11831199 let manifest_diff =
11841200 crate :: container:: ManifestDiff :: new ( & manifest_old, & manifest_new) ;
1185- manifest_diff. print ( ) ;
1201+ if json {
1202+ println ! ( "{:#?}" , serde_json:: to_string( & manifest_diff) ) ;
1203+ } else {
1204+ manifest_diff. print ( ) ;
1205+ }
11861206 Ok ( ( ) )
11871207 }
11881208 } ,
0 commit comments