-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(main): add cmd group for build image
- Loading branch information
1 parent
b817540
commit d3e149f
Showing
8 changed files
with
136 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pub mod cli; | ||
pub mod cli_build; | ||
|
||
pub use cli::*; | ||
pub use cli_build::*; | ||
#[allow(clippy::module_inception)] | ||
mod cli; | ||
mod cli_build; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub use cli::*; | ||
pub use logger::*; | ||
|
||
mod cli; | ||
mod logger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::io::Write; | ||
|
||
use colored::Colorize; | ||
use env_logger::Builder; | ||
use log::{Level, LevelFilter}; | ||
|
||
pub fn init_logger(filter: LevelFilter) { | ||
Builder::new() | ||
.format(|buf, record| { | ||
let level_color = match record.level() { | ||
Level::Error => "ERROR".red(), | ||
Level::Warn => "WARN".yellow(), | ||
Level::Info => "INFO".green(), | ||
Level::Debug => "DEBUG".blue(), | ||
Level::Trace => "TRACE".white(), | ||
}; | ||
writeln!( | ||
buf, | ||
"{} [{}] - {}", | ||
chrono::Local::now() | ||
.format("%Y-%m-%d %H:%M:%S") | ||
.to_string() | ||
.cyan(), | ||
level_color, | ||
record.args() | ||
) | ||
}) | ||
.filter(None, filter) | ||
.init(); | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use log::{debug, error, info, trace, warn}; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_logging() { | ||
init_logger(LevelFilter::Trace); | ||
info!("{}", "This is another info message with color"); | ||
error!("{}", "This is error msg"); | ||
warn!("{}", "This is warn msg"); | ||
debug!("{}", "This is debug msg"); | ||
trace!("{}", "This is trace msg"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub use logger::*; | ||
#[allow(clippy::module_inception)] | ||
mod logger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
use clap::Parser; | ||
use log::{info, trace, LevelFilter}; | ||
use rust_embed::Embed; | ||
|
||
use rbuild_runtime::{init_logger, BuildRuntimeOpts, LogLevel}; | ||
|
||
#[derive(Embed)] | ||
#[folder = "files/"] | ||
struct Asset; | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
let asset = Asset::get("sealos").unwrap(); | ||
println!("asset: {:?}", asset.data.len()); | ||
let opts: BuildRuntimeOpts = BuildRuntimeOpts::parse(); | ||
let level = match opts.log_level { | ||
LogLevel::ERROR => LevelFilter::Error, | ||
LogLevel::INFO => LevelFilter::Info, | ||
LogLevel::WARN => LevelFilter::Warn, | ||
LogLevel::DEBUG => LevelFilter::Debug, | ||
LogLevel::TRACE => LevelFilter::Trace, | ||
}; | ||
init_logger(level); | ||
info!("log level set to: {:?}", opts.log_level); | ||
trace!("asset: {:?}", asset.data.len()); | ||
} |