29 lines
1.0 KiB
Rust
29 lines
1.0 KiB
Rust
//! Argument matching shared by the command groups of the CLI.
|
|
|
|
use leleka_control_plane::{BoxError, model};
|
|
|
|
/// The outcome of one command of a group; `None` when the arguments are not for it.
|
|
pub(super) type Outcome = Option<Result<(), BoxError>>;
|
|
|
|
/// The action and the remaining arguments of a `model <action> ...` command line.
|
|
pub(super) fn model_action(args: &[String]) -> Option<(&str, &[String])> {
|
|
let [group, action, rest @ ..] = args else {
|
|
return None;
|
|
};
|
|
(group == "model").then_some((action.as_str(), rest))
|
|
}
|
|
|
|
/// True when every `(value, expected)` pair matches.
|
|
pub(super) fn flags(pairs: &[(&String, &str)]) -> bool {
|
|
pairs.iter().all(|(value, expected)| *value == expected)
|
|
}
|
|
|
|
/// The total size of the source shards of a manifest.
|
|
pub(super) fn sharded_source_bytes(manifest: &model::Manifest) -> Result<u64, BoxError> {
|
|
Ok(manifest
|
|
.files
|
|
.iter()
|
|
.try_fold(0u64, |sum, file| sum.checked_add(file.size))
|
|
.ok_or("sharded source byte count overflow")?)
|
|
}
|