-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
40 lines (37 loc) · 1.04 KB
/
lib.rs
File metadata and controls
40 lines (37 loc) · 1.04 KB
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
38
39
40
mod check;
pub mod commands;
pub mod config;
mod database;
mod fix;
mod fspath;
pub mod input;
mod output;
pub mod prelude;
pub mod test;
use camino::Utf8Path;
pub use config::Config;
use database::Tikibase;
pub use fix::Fix;
use input::Command;
pub use output::{Message, Messages};
pub use prelude::{Result, UserError};
// TODO
// - replace Utf8Paths with Path
// - use UserError everywhere
// - extract string literals into consts
/// runs the given Command in the given directory, returns structured data
#[must_use]
pub fn run<P: AsRef<Utf8Path>>(command: input::Command, dir: P) -> Messages {
let mut base = match Tikibase::load(dir.as_ref()) {
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)
}