From fbedc548adda5a4e0bf390a9f2835ebf4c841679 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 1 Jul 2024 18:10:40 -0400 Subject: [PATCH 1/2] status: Add --format-version In preparation for us changing the default output of `bootc status` in the future (cc https://github.com/containers/bootc/issues/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 --- lib/src/cli.rs | 15 +++++++++++++++ lib/src/status.rs | 4 ++++ tests/booted/001-test-status.nu | 2 ++ tests/booted/basic.py | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index f4b4077fc..c949b351f 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -130,6 +130,13 @@ pub(crate) struct StatusOpts { #[clap(long)] pub(crate) format: Option, + /// 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, + /// Only display status for the booted deployment. #[clap(long)] pub(crate) booted: bool, @@ -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] diff --git a/lib/src/status.rs b/lib/src/status.rs index 59ab31f85..65386ff38 100644 --- a/lib/src/status.rs +++ b/lib/src/status.rs @@ -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 { diff --git a/tests/booted/001-test-status.nu b/tests/booted/001-test-status.nu index 0d7d559cf..3afe17fd6 100644 --- a/tests/booted/001-test-status.nu +++ b/tests/booted/001-test-status.nu @@ -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 diff --git a/tests/booted/basic.py b/tests/booted/basic.py index 6253c13d7..18524eb8f 100644 --- a/tests/booted/basic.py +++ b/tests/booted/basic.py @@ -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 From e9ce182f35bee92d5398de97c2d2f95b3158dd75 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 1 Jul 2024 18:11:50 -0400 Subject: [PATCH 2/2] docs: Regenerate manpage markdown Signed-off-by: Colin Walters --- docs/src/man/bootc-container-lint.md | 2 +- docs/src/man/bootc-container.md | 2 +- docs/src/man/bootc-edit.md | 2 +- docs/src/man/bootc-install-print-configuration.md | 2 +- docs/src/man/bootc-install-to-disk.md | 2 +- docs/src/man/bootc-install-to-existing-root.md | 2 +- docs/src/man/bootc-install-to-filesystem.md | 2 +- docs/src/man/bootc-install.md | 2 +- docs/src/man/bootc-rollback.md | 2 +- docs/src/man/bootc-status.md | 13 ++++++++++--- docs/src/man/bootc-switch.md | 2 +- docs/src/man/bootc-upgrade.md | 2 +- docs/src/man/bootc-usr-overlay.md | 2 +- docs/src/man/bootc.md | 2 +- 14 files changed, 23 insertions(+), 16 deletions(-) diff --git a/docs/src/man/bootc-container-lint.md b/docs/src/man/bootc-container-lint.md index ec08a6b2a..992b8afdd 100644 --- a/docs/src/man/bootc-container-lint.md +++ b/docs/src/man/bootc-container-lint.md @@ -23,4 +23,4 @@ part of a build process; it will error if any problems are detected. # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-container.md b/docs/src/man/bootc-container.md index afab846ed..10ebfa4ab 100644 --- a/docs/src/man/bootc-container.md +++ b/docs/src/man/bootc-container.md @@ -30,4 +30,4 @@ bootc-container-help(8) # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-edit.md b/docs/src/man/bootc-edit.md index 5f791e86d..28d8984fd 100644 --- a/docs/src/man/bootc-edit.md +++ b/docs/src/man/bootc-edit.md @@ -36,4 +36,4 @@ Only changes to the \`spec\` section are honored. # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-install-print-configuration.md b/docs/src/man/bootc-install-print-configuration.md index 092cf041e..51eb457e3 100644 --- a/docs/src/man/bootc-install-print-configuration.md +++ b/docs/src/man/bootc-install-print-configuration.md @@ -27,4 +27,4 @@ string-valued filesystem name suitable for passing to \`mkfs.\$type\`. # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-install-to-disk.md b/docs/src/man/bootc-install-to-disk.md index 20e872632..001099d5f 100644 --- a/docs/src/man/bootc-install-to-disk.md +++ b/docs/src/man/bootc-install-to-disk.md @@ -144,4 +144,4 @@ firmware will be skipped # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-install-to-existing-root.md b/docs/src/man/bootc-install-to-existing-root.md index 46e8375f1..bdf728920 100644 --- a/docs/src/man/bootc-install-to-existing-root.md +++ b/docs/src/man/bootc-install-to-existing-root.md @@ -130,4 +130,4 @@ firmware will be skipped # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-install-to-filesystem.md b/docs/src/man/bootc-install-to-filesystem.md index 764194164..9264d1aff 100644 --- a/docs/src/man/bootc-install-to-filesystem.md +++ b/docs/src/man/bootc-install-to-filesystem.md @@ -157,4 +157,4 @@ mounting. To override this, use \`\--root-mount-spec\`. # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-install.md b/docs/src/man/bootc-install.md index ac2c7cef2..8ab0f7976 100644 --- a/docs/src/man/bootc-install.md +++ b/docs/src/man/bootc-install.md @@ -61,4 +61,4 @@ bootc-install-help(8) # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-rollback.md b/docs/src/man/bootc-rollback.md index 5d95b1c08..66f28b332 100644 --- a/docs/src/man/bootc-rollback.md +++ b/docs/src/man/bootc-rollback.md @@ -34,4 +34,4 @@ rollback invocation. # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-status.md b/docs/src/man/bootc-status.md index de2442972..d6317dafd 100644 --- a/docs/src/man/bootc-status.md +++ b/docs/src/man/bootc-status.md @@ -4,8 +4,8 @@ bootc-status - Display status # SYNOPSIS -**bootc status** \[**\--format**\] \[**\--booted**\] -\[**-h**\|**\--help**\] +**bootc status** \[**\--format**\] \[**\--format-version**\] +\[**\--booted**\] \[**-h**\|**\--help**\] # DESCRIPTION @@ -30,6 +30,13 @@ The exact API format is not currently declared stable. > > - json: Output in JSON format +**\--format-version**=*FORMAT_VERSION* + +: 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 + **\--booted** : Only display status for the booted deployment @@ -40,4 +47,4 @@ The exact API format is not currently declared stable. # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-switch.md b/docs/src/man/bootc-switch.md index a007c69c0..09a945dfb 100644 --- a/docs/src/man/bootc-switch.md +++ b/docs/src/man/bootc-switch.md @@ -61,4 +61,4 @@ includes a default policy which requires signatures. # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-upgrade.md b/docs/src/man/bootc-upgrade.md index be3cf86a2..c88fec88d 100644 --- a/docs/src/man/bootc-upgrade.md +++ b/docs/src/man/bootc-upgrade.md @@ -52,4 +52,4 @@ userspace-only restart. # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc-usr-overlay.md b/docs/src/man/bootc-usr-overlay.md index b50b206bf..e75411aeb 100644 --- a/docs/src/man/bootc-usr-overlay.md +++ b/docs/src/man/bootc-usr-overlay.md @@ -39,4 +39,4 @@ unmount\". # VERSION -v0.1.12 +v0.1.13 diff --git a/docs/src/man/bootc.md b/docs/src/man/bootc.md index 618836ccc..21ffc99dc 100644 --- a/docs/src/man/bootc.md +++ b/docs/src/man/bootc.md @@ -72,4 +72,4 @@ bootc-help(8) # VERSION -v0.1.12 +v0.1.13