mirror of
https://github.com/marcoallegretti/karapace.git
synced 2026-03-26 21:43:09 +00:00
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:
parent
52b42532ce
commit
eff53cf7af
5 changed files with 22 additions and 40 deletions
|
|
@ -8,9 +8,7 @@ pub fn run(
|
|||
store_path: &Path,
|
||||
manifest: &Path,
|
||||
name: Option<&str>,
|
||||
locked: bool,
|
||||
offline: bool,
|
||||
require_pinned_image: bool,
|
||||
options: BuildOptions,
|
||||
json: bool,
|
||||
) -> Result<u8, String> {
|
||||
let layout = StoreLayout::new(store_path);
|
||||
|
|
@ -21,12 +19,6 @@ pub fn run(
|
|||
} else {
|
||||
Some(spinner("building environment..."))
|
||||
};
|
||||
let options = BuildOptions {
|
||||
locked,
|
||||
offline,
|
||||
require_pinned_image,
|
||||
};
|
||||
|
||||
let result = match engine.build_with_options(manifest, options) {
|
||||
Ok(r) => {
|
||||
if let Some(ref pb) = pb {
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ pub fn run(
|
|||
json: bool,
|
||||
store_path: Option<&Path>,
|
||||
) -> Result<u8, String> {
|
||||
let manifest = parse_manifest_file(manifest_path)
|
||||
.map_err(|e| format!("failed to parse manifest: {e}"))?;
|
||||
let manifest =
|
||||
parse_manifest_file(manifest_path).map_err(|e| format!("failed to parse manifest: {e}"))?;
|
||||
|
||||
if check {
|
||||
if is_pinned(&manifest.base.image) {
|
||||
|
|
@ -65,9 +65,7 @@ pub fn run(
|
|||
if write_lock {
|
||||
let store = store_path.ok_or_else(|| "internal error: missing store path".to_owned())?;
|
||||
let engine = karapace_core::Engine::new(store);
|
||||
engine
|
||||
.build(manifest_path)
|
||||
.map_err(|e| e.to_string())?;
|
||||
engine.build(manifest_path).map_err(|e| e.to_string())?;
|
||||
}
|
||||
|
||||
if json {
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@ pub fn run(
|
|||
store_path: &Path,
|
||||
manifest: &Path,
|
||||
name: Option<&str>,
|
||||
locked: bool,
|
||||
offline: bool,
|
||||
require_pinned_image: bool,
|
||||
options: BuildOptions,
|
||||
json: bool,
|
||||
) -> Result<u8, String> {
|
||||
let layout = StoreLayout::new(store_path);
|
||||
|
|
@ -21,12 +19,6 @@ pub fn run(
|
|||
} else {
|
||||
Some(spinner("rebuilding environment..."))
|
||||
};
|
||||
let options = BuildOptions {
|
||||
locked,
|
||||
offline,
|
||||
require_pinned_image,
|
||||
};
|
||||
|
||||
let result = match engine.rebuild_with_options(manifest, options) {
|
||||
Ok(r) => {
|
||||
if let Some(ref pb) = pb {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ mod commands;
|
|||
use clap::{Parser, Subcommand};
|
||||
use clap_complete::Shell;
|
||||
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::process::ExitCode;
|
||||
|
||||
|
|
@ -273,9 +273,11 @@ fn main() -> ExitCode {
|
|||
&store_path,
|
||||
&manifest,
|
||||
name.as_deref(),
|
||||
locked,
|
||||
offline,
|
||||
require_pinned_image,
|
||||
BuildOptions {
|
||||
locked,
|
||||
offline,
|
||||
require_pinned_image,
|
||||
},
|
||||
json_output,
|
||||
),
|
||||
Commands::Rebuild {
|
||||
|
|
@ -289,22 +291,18 @@ fn main() -> ExitCode {
|
|||
&store_path,
|
||||
&manifest,
|
||||
name.as_deref(),
|
||||
locked,
|
||||
offline,
|
||||
require_pinned_image,
|
||||
BuildOptions {
|
||||
locked,
|
||||
offline,
|
||||
require_pinned_image,
|
||||
},
|
||||
json_output,
|
||||
),
|
||||
Commands::Pin {
|
||||
manifest,
|
||||
check,
|
||||
write_lock,
|
||||
} => commands::pin::run(
|
||||
&manifest,
|
||||
check,
|
||||
write_lock,
|
||||
json_output,
|
||||
Some(&store_path),
|
||||
),
|
||||
} => commands::pin::run(&manifest, check, write_lock, json_output, Some(&store_path)),
|
||||
Commands::Enter { env_id, command } => {
|
||||
commands::enter::run(&engine, &store_path, &env_id, &command)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,9 +172,11 @@ impl Engine {
|
|||
let normalized = manifest.normalize()?;
|
||||
|
||||
if options.offline && !normalized.system_packages.is_empty() {
|
||||
return Err(CoreError::Runtime(karapace_runtime::RuntimeError::ExecFailed(
|
||||
"offline mode: cannot resolve system packages".to_owned(),
|
||||
)));
|
||||
return Err(CoreError::Runtime(
|
||||
karapace_runtime::RuntimeError::ExecFailed(
|
||||
"offline mode: cannot resolve system packages".to_owned(),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
if options.require_pinned_image
|
||||
|
|
|
|||
Loading…
Reference in a new issue