cli/transaction/
rows_args.rs1use clap::{Arg, ArgAction};
6use forms::{Field, Kind, SPLIT_TAGS_KEY, SPLITS_KEY as SPLITS};
7
8const TAG_CELLS: [&str; 3] = ["name", "value", "side"];
9
10pub(super) fn is_free_rows(field: &Field) -> bool {
11 matches!(field.kind, Kind::Rows { .. }) && !field.is_nested() && field.key != SPLITS
12}
13
14pub(super) fn is_nested_tags(field: &Field) -> bool {
17 match field.kind {
18 Kind::Rows { fields, .. }
19 if field.key == SPLIT_TAGS_KEY && field.nested_under() == Some(SPLITS) =>
20 {
21 TAG_CELLS
22 .iter()
23 .all(|cell| fields.iter().any(|f| f.key == *cell))
24 }
25 _ => false,
26 }
27}
28
29pub(super) fn is_carried(field: &Field) -> bool {
31 field.is_nested() && !is_nested_tags(field)
32}
33
34pub(super) fn has_clear(field: &Field) -> bool {
35 is_free_rows(field) || is_nested_tags(field)
36}
37
38pub(super) fn row_long(field: &Field) -> &'static str {
40 match field.key {
41 SPLITS => "row",
42 key => key.strip_suffix('s').unwrap_or(key),
43 }
44}
45
46pub(super) fn clear_id(field: &Field) -> String {
47 format!("clear-{}", field.key)
48}
49
50pub(super) fn clear_arg(field: &Field) -> Arg {
51 let id = clear_id(field);
52 Arg::new(id.clone())
53 .long(id)
54 .action(ArgAction::SetTrue)
55 .conflicts_with(field.key)
56 .help(format!("Send an empty {} list", field.label))
57}