-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
40 lines (36 loc) · 1.02 KB
/
main.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
38
39
40
//! the CLI wrapper around lib.rs
use clap::StructOpt;
use input::Format::{Json, Text};
use std::io;
use std::process::ExitCode;
use tikibase::input::Command;
use tikibase::{input, run, Message, Messages};
fn main() -> ExitCode {
let args = input::Arguments::parse();
let messages = run(args.command, ".");
let exit_code = messages.exit_code;
match args.format {
Text => print_text(&messages, args.command),
Json => print_json(&messages.all()),
};
ExitCode::from(exit_code)
}
fn print_text(messages: &Messages, command: Command) {
if command != Command::Fix {
for issue in &messages.issues {
println!("{}", issue.to_text());
}
}
if messages.has_issues_and_fixes() {
println!();
}
for fix in &messages.fixes {
println!("{}", fix.to_text());
}
}
fn print_json(messages: &[Message]) {
// NOTE: using a buffered writer doesn't seem to improve performance here
if let Err(err) = serde_json::to_writer_pretty(io::stdout(), messages) {
println!("Error serializing JSON: {err}");
}
}