Skip to content
Open
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
4 changes: 2 additions & 2 deletions crates/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ pub(crate) enum InstallOpts {
///
/// At the current time, the only output key is `root-fs-type` which is a string-valued
/// filesystem name suitable for passing to `mkfs.$type`.
PrintConfiguration,
PrintConfiguration(crate::install::InstallPrintConfigurationOpts),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the change itself is correct, it would be beneficial to add a unit test to verify the parsing of the new --all flag for the install print-configuration subcommand. This ensures future changes don't accidentally break this functionality.

You could add a new test function in the tests module of this file, similar to test_parse_install_args. For example:

#[test]
fn test_parse_print_configuration() {
    // Default, no --all
    let o = Opt::try_parse_from(["bootc", "install", "print-configuration"]).unwrap();
    let o = match o {
        Opt::Install(InstallOpts::PrintConfiguration(opts)) => opts,
        o => panic!("Expected print-configuration opts, not {o:?}"),
    };
    assert!(!o.all);

    // With --all
    let o = Opt::try_parse_from(["bootc", "install", "print-configuration", "--all"]).unwrap();
    let o = match o {
        Opt::Install(InstallOpts::PrintConfiguration(opts)) => opts,
        o => panic!("Expected print-configuration opts, not {o:?}"),
    };
    assert!(o.all);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are good, but we can't really do this in unit tests because it operates on ambient data.

We can do it in tests-integration/src/container.rs though I think.

}

/// Subcommands which can be executed as part of a container build.
Expand Down Expand Up @@ -1483,7 +1483,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
crate::install::install_to_existing_root(opts).await
}
InstallOpts::Reset(opts) => crate::install::install_reset(opts).await,
InstallOpts::PrintConfiguration => crate::install::print_configuration(),
InstallOpts::PrintConfiguration(opts) => crate::install::print_configuration(opts),
InstallOpts::EnsureCompletion {} => {
let rootfs = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
crate::install::completion::run_from_anaconda(rootfs).await
Expand Down
15 changes: 13 additions & 2 deletions crates/lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,15 @@ pub(crate) struct InstallResetOpts {
karg: Option<Vec<CmdlineOwned>>,
}

#[derive(Debug, clap::Parser, PartialEq, Eq)]
pub(crate) struct InstallPrintConfigurationOpts {
/// Print all configuration.
///
/// Print configuration that is usually handled internally, like kargs.
#[clap(long)]
pub(crate) all: bool,
}

/// Global state captured from the container.
#[derive(Debug, Clone)]
pub(crate) struct SourceInfo {
Expand Down Expand Up @@ -722,9 +731,11 @@ impl SourceInfo {
}
}

pub(crate) fn print_configuration() -> Result<()> {
pub(crate) fn print_configuration(opts: InstallPrintConfigurationOpts) -> Result<()> {
let mut install_config = config::load_config()?.unwrap_or_default();
install_config.filter_to_external();
if !opts.all {
install_config.filter_to_external();
}
let stdout = std::io::stdout().lock();
anyhow::Ok(install_config.to_canon_json_writer(stdout)?)
}
Expand Down
Loading