Skip to content

Commit

Permalink
status: Add --format-version
Browse files Browse the repository at this point in the history
In preparation for us changing the default output of `bootc status`
in the future (cc containers#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]>
  • Loading branch information
cgwalters committed Jul 1, 2024
1 parent dad29ac commit fbedc54
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ pub(crate) struct StatusOpts {
#[clap(long)]
pub(crate) format: Option<OutputFormat>,

/// The desired format version. There is currently one supported
/// version, which is version `0`. Pass this option to explicitly
/// request it; it is possible that multiple versions will be
/// supported in the future.
#[clap(long)]
pub(crate) format_version: Option<u32>,

/// Only display status for the booted deployment.
#[clap(long)]
pub(crate) booted: bool,
Expand Down Expand Up @@ -837,9 +844,17 @@ fn test_parse_opts() {
Opt::Status(StatusOpts {
json: false,
format: None,
format_version: None,
booted: false
})
));
assert!(matches!(
Opt::parse_including_static(["bootc", "status", "--format-version=0"]),
Opt::Status(StatusOpts {
format_version: Some(0),
..
})
));
}

#[test]
Expand Down
4 changes: 4 additions & 0 deletions lib/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ pub(crate) fn get_status(
/// Implementation of the `bootc status` CLI command.
#[context("Status")]
pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
match opts.format_version.unwrap_or_default() {
0 => {}
o => anyhow::bail!("Unsupported format version: {o}"),
};
let host = if !Utf8Path::new("/run/ostree-booted").try_exists()? {
Default::default()
} else {
Expand Down
2 changes: 2 additions & 0 deletions tests/booted/001-test-status.nu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ tap begin "verify bootc status output formats"

let st = bootc status --json | from json
assert equal $st.apiVersion org.containers.bootc/v1alpha1
let st = bootc status --json --format-version=0 | from json
assert equal $st.apiVersion org.containers.bootc/v1alpha1
let st = bootc status --format=yaml | from yaml
assert equal $st.apiVersion org.containers.bootc/v1alpha1
tap ok
4 changes: 4 additions & 0 deletions tests/booted/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ def test_bootc_status():
o = subprocess.check_output(["bootc", "status", "--json"])
st = json.loads(o)
assert st['apiVersion'] == 'org.containers.bootc/v1alpha1'

def test_bootc_status_invalid_version():
o = subprocess.call(["bootc", "status", "--json", "--format-version=42"])
assert o != 0

0 comments on commit fbedc54

Please sign in to comment.