use crate::ported::commands::lint::get_argparser;
pub fn main(args: &[String]) -> i32 {
let _parser = get_argparser();
let mut config_paths: Vec<String> = Vec::new();
let mut debug = false;
let mut i = 0;
while i < args.len() {
match args[i].as_str() {
"--config-path" | "-p" => {
i += 1;
if let Some(p) = args.get(i) {
config_paths.push(p.clone());
}
}
"--debug" | "-d" => {
debug = true;
}
_ => {}
}
i += 1;
}
let _ = debug;
if config_paths.is_empty() {
eprintln!("powerline-lint: --config-path is required");
return 2;
}
let hadproblem = crate::ported::lint::check(Some(&config_paths), debug, None);
if hadproblem {
1
} else {
0
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn main_returns_2_when_no_config_path() {
assert_eq!(main(&[]), 2);
}
#[test]
fn main_returns_0_when_config_path_supplied_long() {
let r = main(&[
"--config-path".to_string(),
"/tmp/powerline-config".to_string(),
]);
assert_eq!(r, 0);
}
#[test]
fn main_returns_0_when_config_path_supplied_short() {
let r = main(&["-p".to_string(), "/tmp/powerline-config".to_string()]);
assert_eq!(r, 0);
}
#[test]
fn main_accepts_debug_flag() {
let r = main(&[
"--config-path".to_string(),
"/tmp/x".to_string(),
"--debug".to_string(),
]);
assert_eq!(r, 0);
}
}