#[derive(Debug, Clone)]
pub struct ArgParser {
pub description: String,
pub arguments: Vec<Argument>,
}
#[derive(Debug, Clone)]
pub struct Argument {
pub flags: Vec<String>, pub action: ArgAction,
pub metavar: Option<String>,
pub help: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ArgAction {
Store,
StoreTrue,
StoreConstTrue,
Append,
}
pub fn get_argparser() -> ArgParser {
ArgParser {
description: "Powerline configuration checker.".to_string(),
arguments: vec![
Argument {
flags: vec!["-p".into(), "--config-path".into()],
action: ArgAction::Append,
metavar: Some("PATH".into()),
help: "Paths where configuration should be checked, in order. You must \
supply all paths necessary for powerline to work, \
checking partial (e.g. only user overrides) configuration \
is not supported."
.to_string(),
},
Argument {
flags: vec!["-d".into(), "--debug".into()],
action: ArgAction::StoreConstTrue,
metavar: None,
help: "Display additional information. Used for debugging \
`powerline-lint' itself, not for debugging configuration."
.to_string(),
},
],
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn lint_parser_description_matches_upstream() {
let p = get_argparser();
assert_eq!(p.description, "Powerline configuration checker.");
}
#[test]
fn lint_parser_has_two_arguments() {
let p = get_argparser();
assert_eq!(p.arguments.len(), 2);
assert!(p.arguments[0].flags.contains(&"--config-path".to_string()));
assert!(p.arguments[1].flags.contains(&"--debug".to_string()));
}
#[test]
fn config_path_uses_append_action() {
let p = get_argparser();
assert_eq!(p.arguments[0].action, ArgAction::Append);
}
}