cli: satisfy clippy and rustfmt

Refactor build and rebuild command handlers to pass BuildOptions instead
of multiple boolean flags, satisfying clippy's excessive-bools and
too-many-arguments lints.

Apply rustfmt output in CLI and core engine code.
This commit is contained in:
Marco Allegretti 2026-02-23 18:50:23 +01:00
parent 52b42532ce
commit eff53cf7af
5 changed files with 22 additions and 40 deletions

View file

@ -8,9 +8,7 @@ pub fn run(
store_path: &Path, store_path: &Path,
manifest: &Path, manifest: &Path,
name: Option<&str>, name: Option<&str>,
locked: bool, options: BuildOptions,
offline: bool,
require_pinned_image: bool,
json: bool, json: bool,
) -> Result<u8, String> { ) -> Result<u8, String> {
let layout = StoreLayout::new(store_path); let layout = StoreLayout::new(store_path);
@ -21,12 +19,6 @@ pub fn run(
} else { } else {
Some(spinner("building environment...")) Some(spinner("building environment..."))
}; };
let options = BuildOptions {
locked,
offline,
require_pinned_image,
};
let result = match engine.build_with_options(manifest, options) { let result = match engine.build_with_options(manifest, options) {
Ok(r) => { Ok(r) => {
if let Some(ref pb) = pb { if let Some(ref pb) = pb {

View file

@ -32,8 +32,8 @@ pub fn run(
json: bool, json: bool,
store_path: Option<&Path>, store_path: Option<&Path>,
) -> Result<u8, String> { ) -> Result<u8, String> {
let manifest = parse_manifest_file(manifest_path) let manifest =
.map_err(|e| format!("failed to parse manifest: {e}"))?; parse_manifest_file(manifest_path).map_err(|e| format!("failed to parse manifest: {e}"))?;
if check { if check {
if is_pinned(&manifest.base.image) { if is_pinned(&manifest.base.image) {
@ -65,9 +65,7 @@ pub fn run(
if write_lock { if write_lock {
let store = store_path.ok_or_else(|| "internal error: missing store path".to_owned())?; let store = store_path.ok_or_else(|| "internal error: missing store path".to_owned())?;
let engine = karapace_core::Engine::new(store); let engine = karapace_core::Engine::new(store);
engine engine.build(manifest_path).map_err(|e| e.to_string())?;
.build(manifest_path)
.map_err(|e| e.to_string())?;
} }
if json { if json {

View file

@ -8,9 +8,7 @@ pub fn run(
store_path: &Path, store_path: &Path,
manifest: &Path, manifest: &Path,
name: Option<&str>, name: Option<&str>,
locked: bool, options: BuildOptions,
offline: bool,
require_pinned_image: bool,
json: bool, json: bool,
) -> Result<u8, String> { ) -> Result<u8, String> {
let layout = StoreLayout::new(store_path); let layout = StoreLayout::new(store_path);
@ -21,12 +19,6 @@ pub fn run(
} else { } else {
Some(spinner("rebuilding environment...")) Some(spinner("rebuilding environment..."))
}; };
let options = BuildOptions {
locked,
offline,
require_pinned_image,
};
let result = match engine.rebuild_with_options(manifest, options) { let result = match engine.rebuild_with_options(manifest, options) {
Ok(r) => { Ok(r) => {
if let Some(ref pb) = pb { if let Some(ref pb) = pb {

View file

@ -3,7 +3,7 @@ mod commands;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use clap_complete::Shell; use clap_complete::Shell;
use commands::{EXIT_FAILURE, EXIT_MANIFEST_ERROR, EXIT_STORE_ERROR}; use commands::{EXIT_FAILURE, EXIT_MANIFEST_ERROR, EXIT_STORE_ERROR};
use karapace_core::{install_signal_handler, Engine}; use karapace_core::{install_signal_handler, BuildOptions, Engine};
use std::path::PathBuf; use std::path::PathBuf;
use std::process::ExitCode; use std::process::ExitCode;
@ -273,9 +273,11 @@ fn main() -> ExitCode {
&store_path, &store_path,
&manifest, &manifest,
name.as_deref(), name.as_deref(),
BuildOptions {
locked, locked,
offline, offline,
require_pinned_image, require_pinned_image,
},
json_output, json_output,
), ),
Commands::Rebuild { Commands::Rebuild {
@ -289,22 +291,18 @@ fn main() -> ExitCode {
&store_path, &store_path,
&manifest, &manifest,
name.as_deref(), name.as_deref(),
BuildOptions {
locked, locked,
offline, offline,
require_pinned_image, require_pinned_image,
},
json_output, json_output,
), ),
Commands::Pin { Commands::Pin {
manifest, manifest,
check, check,
write_lock, write_lock,
} => commands::pin::run( } => commands::pin::run(&manifest, check, write_lock, json_output, Some(&store_path)),
&manifest,
check,
write_lock,
json_output,
Some(&store_path),
),
Commands::Enter { env_id, command } => { Commands::Enter { env_id, command } => {
commands::enter::run(&engine, &store_path, &env_id, &command) commands::enter::run(&engine, &store_path, &env_id, &command)
} }

View file

@ -172,9 +172,11 @@ impl Engine {
let normalized = manifest.normalize()?; let normalized = manifest.normalize()?;
if options.offline && !normalized.system_packages.is_empty() { if options.offline && !normalized.system_packages.is_empty() {
return Err(CoreError::Runtime(karapace_runtime::RuntimeError::ExecFailed( return Err(CoreError::Runtime(
karapace_runtime::RuntimeError::ExecFailed(
"offline mode: cannot resolve system packages".to_owned(), "offline mode: cannot resolve system packages".to_owned(),
))); ),
));
} }
if options.require_pinned_image if options.require_pinned_image