Lines
100 %
Functions
Branches
//! Option names for `rows` fields: `splits` keeps `--row`, others get
//! `--<singular>` and `--clear-<key>`. A nested tag field is optioned too; any
//! other nested field has no option.
use clap::{Arg, ArgAction};
use forms::{Field, Kind, SPLIT_TAGS_KEY, SPLITS_KEY as SPLITS};
const TAG_CELLS: [&str; 3] = ["name", "value", "side"];
pub(super) fn is_free_rows(field: &Field) -> bool {
matches!(field.kind, Kind::Rows { .. }) && !field.is_nested() && field.key != SPLITS
}
/// The split tags field: the one nested field the linker handles, whose
/// cells are name, value and the leg they apply to.
pub(super) fn is_nested_tags(field: &Field) -> bool {
match field.kind {
Kind::Rows { fields, .. }
if field.key == SPLIT_TAGS_KEY && field.nested_under() == Some(SPLITS) =>
{
TAG_CELLS
.iter()
.all(|cell| fields.iter().any(|f| f.key == *cell))
_ => false,
/// Nested fields the commands carry from the loaded form without an option.
pub(super) fn is_carried(field: &Field) -> bool {
field.is_nested() && !is_nested_tags(field)
pub(super) fn has_clear(field: &Field) -> bool {
is_free_rows(field) || is_nested_tags(field)
/// The row option's long name: `row` for splits, else the key minus one trailing `s`.
pub(super) fn row_long(field: &Field) -> &'static str {
match field.key {
SPLITS => "row",
key => key.strip_suffix('s').unwrap_or(key),
pub(super) fn clear_id(field: &Field) -> String {
format!("clear-{}", field.key)
pub(super) fn clear_arg(field: &Field) -> Arg {
let id = clear_id(field);
Arg::new(id.clone())
.long(id)
.action(ArgAction::SetTrue)
.conflicts_with(field.key)
.help(format!("Send an empty {} list", field.label))