Skip to main content

argot_cli/
macros.rs

1#[macro_export]
2macro_rules! entries {
3    (
4        $( $key:literal => $variant:ident $( { $( $field:ident : $value:expr ),* $(,)? } )? ),* $(,)?
5    ) => {{
6        let mut map = ::std::collections::HashMap::new();
7        $(
8            map.insert(
9                $key.into(),
10                $crate::entries!(@build $variant $( { $( $field : $value ),* } )?)
11            );
12        )*
13        $crate::arg_parser::ParserConfig::new($crate::types::ConfigEntries::Map(map))
14    }};
15
16    (@build Flag $({})?) => {
17        $crate::types::ConfigEntry::Flag
18    };
19
20    (@build Text $({})?) => {
21        $crate::types::ConfigEntry::Text { default: None }
22    };
23
24    (@build Text { default: $val:expr }) => {
25        $crate::types::ConfigEntry::Text { default: Some($val.into()) }
26    };
27
28    (@build Int $({})?) => {
29        $crate::types::ConfigEntry::Int { default: None }
30    };
31
32    (@build Int { default: $val:expr }) => {
33        $crate::types::ConfigEntry::Int { default: Some($val) }
34    };
35
36    (@build Count $({})?) => {
37        $crate::types::ConfigEntry::Count
38    };
39
40    (@build List $({})?) => {
41        $crate::types::ConfigEntry::List { sep: None }
42    };
43
44    (@build List { sep: $val:expr }) => {
45        $crate::types::ConfigEntry::List { sep: Some($val.into()) }
46    };
47
48    (@build Alias { target: $val:expr }) => {
49        $crate::types::ConfigEntry::Alias { target: $val.into() }
50    };
51
52    (@build $unknown:ident $($rest:tt)*) => {
53        compile_error!(concat!("unsupported entry type: ", stringify!($unknown)));
54    };
55}