1extern crate cargo_metadata;
2extern crate cmake_config;
3extern crate colored;
4extern crate fel4_config;
5#[macro_use]
6extern crate log;
7#[macro_use]
8extern crate structopt;
9
10use colored::Colorize;
11use std::fmt;
12use std::io;
13
14mod build_cmd;
15mod clean_cmd;
16mod cmake_codegen;
17mod command_ext;
18mod config;
19mod deploy_cmd;
20mod generator;
21mod new_cmd;
22mod simulate_cmd;
23mod test_cmd;
24
25pub use build_cmd::handle_build_cmd;
26pub use clean_cmd::handle_clean_cmd;
27pub use config::{
28 BuildCmd, CargoFel4Cli, CleanCmd, Fel4SubCmd, LoudnessOpts, NewCmd, ResolvedConfig,
29 SimulateCmd, TestCmd, TestSubCmd,
30};
31pub use deploy_cmd::handle_deploy_cmd;
32pub use new_cmd::handle_new_cmd;
33pub use simulate_cmd::handle_simulate_cmd;
34pub use test_cmd::handle_test_cmd;
35
36#[derive(Clone, Debug, Eq, PartialEq, Hash)]
37pub enum Error {
38 ConfigError(String),
39 IO(String),
40 ExitStatusError(String),
41}
42
43impl From<io::Error> for Error {
44 fn from(e: io::Error) -> Self {
45 Error::IO(format!("{}", e))
46 }
47}
48
49impl From<cargo_metadata::Error> for Error {
50 fn from(e: cargo_metadata::Error) -> Self {
51 Error::ConfigError(format!("{}", e))
52 }
53}
54
55impl fmt::Display for Error {
56 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57 match self {
58 Error::IO(msg) => write!(f, "[IO error] {}", msg),
59 Error::ExitStatusError(msg) => write!(f, "[command error] {}", msg),
60 Error::ConfigError(msg) => write!(
61 f,
62 "[config error] {}\n\nCheck your project's toml files for invalid syntax",
63 msg
64 ),
65 }
66 }
67}
68
69pub struct Logger;
70
71impl log::Log for Logger {
72 fn enabled(&self, metadata: &log::Metadata) -> bool {
73 metadata.level() <= log::Level::Info
74 }
75
76 fn log(&self, record: &log::Record) {
79 if self.enabled(record.metadata()) {
80 println!(
81 "{}: {}",
82 match record.level() {
83 log::Level::Error => "error".red(),
84 log::Level::Warn => "warn".bright_yellow(),
85 log::Level::Info => "info".bright_green(),
86 l => l.to_string().to_lowercase().normal(),
87 },
88 record.args()
89 );
90 }
91 }
92
93 fn flush(&self) {}
94}