mint_cli/layout/
args.rs

1use super::errors::LayoutError;
2use clap::Args;
3
4#[derive(Debug, Clone)]
5pub struct BlockNames {
6    pub name: String,
7    pub file: String,
8}
9
10pub fn parse_block_arg(block: &str) -> Result<BlockNames, LayoutError> {
11    let parts: Vec<&str> = block.split('@').collect();
12
13    match parts.len() {
14        2 => Ok(BlockNames {
15            name: parts[0].to_string(),
16            file: parts[1].to_string(),
17        }),
18        1 => Ok(BlockNames {
19            name: String::new(),
20            file: parts[0].to_string(),
21        }),
22        _ => Err(LayoutError::InvalidBlockArgument(format!(
23            "Failed to unpack block {}",
24            block
25        ))),
26    }
27}
28
29#[derive(Args, Debug)]
30pub struct LayoutArgs {
31    #[arg(value_name = "BLOCK@FILE | FILE", num_args = 1.., value_parser = parse_block_arg, help = "One or more blocks as name@layout_file or a layout_file (toml/yaml/json) to build all blocks")]
32    pub blocks: Vec<BlockNames>,
33
34    #[arg(
35        long,
36        help = "Enable strict type conversions; disallow lossy casts during bytestream assembly",
37        default_value_t = false
38    )]
39    pub strict: bool,
40}