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 if parts.len() != 2 {
14 Err(LayoutError::InvalidBlockArgument(format!(
15 "Failed to unpack block {}",
16 block
17 )))
18 } else {
19 Ok(BlockNames {
20 name: parts[0].to_string(),
21 file: parts[1].to_string(),
22 })
23 }
24}
25
26#[derive(Args, Debug)]
27pub struct LayoutArgs {
28 #[arg(value_name = "BLOCK@FILE", num_args = 1.., value_parser = parse_block_arg, help = "One or more blocks in the form name@layout_file (toml/yaml/json)")]
29 pub blocks: Vec<BlockNames>,
30
31 #[arg(
32 long,
33 help = "Enable strict type conversions; disallow lossy casts during bytestream assembly",
34 default_value_t = false
35 )]
36 pub strict: bool,
37}