-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
37 lines (35 loc) · 1.02 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
mod check;
pub mod commands;
pub mod config;
mod database;
mod fix;
pub mod input;
mod output;
pub mod test;
pub use config::Config;
use database::Tikibase;
pub use fix::Fix;
use input::Command;
pub use output::{Message, Messages};
/// runs the given Command in the given directory, returns structured data
#[must_use]
pub fn run(command: input::Command, dir: &str) -> Messages {
if command == Command::Init {
return Messages::from_outcome(commands::init(dir));
}
if command == Command::JsonSchema {
return Messages::from_outcome(commands::json_schema());
}
let mut base = match Tikibase::load(dir.into()) {
Ok(base) => base,
Err(issues) => return Messages::from_issues(issues),
};
let outcome = match command {
Command::Check => commands::check(&base),
Command::Stats => commands::stats(&base),
Command::Fix => commands::fix(&mut base),
Command::P => commands::pitstop(&mut base),
Command::Init | Command::JsonSchema => panic!(), // handled above
};
Messages::from_outcome(outcome)
}