Skip to content

Commit fbedc54

Browse files
committed
status: Add --format-version
In preparation for us changing the default output of `bootc status` in the future (cc bootc-dev#518 ) add `--format-version` that people can start using now to explicitly request the current version. It's possible that instead of a hard break we still support outputting the current format for a while. Signed-off-by: Colin Walters <[email protected]>
1 parent dad29ac commit fbedc54

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

lib/src/cli.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ pub(crate) struct StatusOpts {
130130
#[clap(long)]
131131
pub(crate) format: Option<OutputFormat>,
132132

133+
/// The desired format version. There is currently one supported
134+
/// version, which is version `0`. Pass this option to explicitly
135+
/// request it; it is possible that multiple versions will be
136+
/// supported in the future.
137+
#[clap(long)]
138+
pub(crate) format_version: Option<u32>,
139+
133140
/// Only display status for the booted deployment.
134141
#[clap(long)]
135142
pub(crate) booted: bool,
@@ -837,9 +844,17 @@ fn test_parse_opts() {
837844
Opt::Status(StatusOpts {
838845
json: false,
839846
format: None,
847+
format_version: None,
840848
booted: false
841849
})
842850
));
851+
assert!(matches!(
852+
Opt::parse_including_static(["bootc", "status", "--format-version=0"]),
853+
Opt::Status(StatusOpts {
854+
format_version: Some(0),
855+
..
856+
})
857+
));
843858
}
844859

845860
#[test]

lib/src/status.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ pub(crate) fn get_status(
304304
/// Implementation of the `bootc status` CLI command.
305305
#[context("Status")]
306306
pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
307+
match opts.format_version.unwrap_or_default() {
308+
0 => {}
309+
o => anyhow::bail!("Unsupported format version: {o}"),
310+
};
307311
let host = if !Utf8Path::new("/run/ostree-booted").try_exists()? {
308312
Default::default()
309313
} else {

tests/booted/001-test-status.nu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ tap begin "verify bootc status output formats"
55

66
let st = bootc status --json | from json
77
assert equal $st.apiVersion org.containers.bootc/v1alpha1
8+
let st = bootc status --json --format-version=0 | from json
9+
assert equal $st.apiVersion org.containers.bootc/v1alpha1
810
let st = bootc status --format=yaml | from yaml
911
assert equal $st.apiVersion org.containers.bootc/v1alpha1
1012
tap ok

tests/booted/basic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ def test_bootc_status():
1010
o = subprocess.check_output(["bootc", "status", "--json"])
1111
st = json.loads(o)
1212
assert st['apiVersion'] == 'org.containers.bootc/v1alpha1'
13+
14+
def test_bootc_status_invalid_version():
15+
o = subprocess.call(["bootc", "status", "--json", "--format-version=42"])
16+
assert o != 0

0 commit comments

Comments
 (0)