improve args management

This commit is contained in:
Clément DOUIN
2022-09-27 17:37:08 +02:00
parent 3feccc3225
commit 329af51534
10 changed files with 740 additions and 707 deletions
+14 -3
View File
@@ -1,10 +1,21 @@
use clap::Arg;
use clap::{Arg, ArgMatches};
/// Defines the max table width argument.
const ARG_MAX_TABLE_WIDTH: &str = "max-table-width";
pub(crate) type MaxTableWidth = Option<usize>;
/// Represents the max table width argument.
pub fn max_width<'a>() -> Arg<'a, 'a> {
Arg::with_name("max-table-width")
Arg::with_name(ARG_MAX_TABLE_WIDTH)
.help("Defines a maximum width for the table")
.short("w")
.long("max-width")
.value_name("INT")
}
/// Represents the max table width argument parser.
pub fn parse_max_width<'a>(matches: &'a ArgMatches<'a>) -> Option<usize> {
matches
.value_of(ARG_MAX_TABLE_WIDTH)
.and_then(|width| width.parse::<usize>().ok())
}