Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status: Add --format-version #661

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/man/bootc-container-lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ part of a build process; it will error if any problems are detected.

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ bootc-container-help(8)

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Only changes to the \`spec\` section are honored.

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-install-print-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ string-valued filesystem name suitable for passing to \`mkfs.\$type\`.

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-install-to-disk.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ firmware will be skipped

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-install-to-existing-root.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ firmware will be skipped

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-install-to-filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ mounting. To override this, use \`\--root-mount-spec\`.

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ bootc-install-help(8)

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-rollback.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ rollback invocation.

# VERSION

v0.1.12
v0.1.13
13 changes: 10 additions & 3 deletions docs/src/man/bootc-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ bootc-status - Display status

# SYNOPSIS

**bootc status** \[**\--format**\] \[**\--booted**\]
\[**-h**\|**\--help**\]
**bootc status** \[**\--format**\] \[**\--format-version**\]
\[**\--booted**\] \[**-h**\|**\--help**\]

# DESCRIPTION

Expand All @@ -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
Expand All @@ -40,4 +47,4 @@ The exact API format is not currently declared stable.

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ includes a default policy which requires signatures.

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ userspace-only restart.

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc-usr-overlay.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ unmount\".

# VERSION

v0.1.12
v0.1.13
2 changes: 1 addition & 1 deletion docs/src/man/bootc.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ bootc-help(8)

# VERSION

v0.1.12
v0.1.13
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
Loading