diff --git a/Cargo.lock b/Cargo.lock index 728843f..62abfd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,7 +72,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rust_util 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rust_util 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "urlencoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1008,7 +1008,7 @@ dependencies = [ [[package]] name = "rust_util" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1602,7 +1602,7 @@ dependencies = [ "checksum reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)" = "2c2064233e442ce85c77231ebd67d9eca395207dec2127fe0bbedde4bd29a650" "checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" -"checksum rust_util 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "35700070bf50662d748fb06926d16d24c1f7d6cfd62ba556dc58541d3c96d436" +"checksum rust_util 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "454c4fd8ae19dd245bdc073cb297e222362adf938c3e6f0c2f8ea1abc7be2fd0" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" diff --git a/Cargo.toml b/Cargo.toml index 659cf7c..10f9e67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,4 @@ urlencoding = "1.0.0" dirs = "2.0.1" rust-crypto = "0.2.36" lazy_static = "1.3.0" -rust_util = "0.2.1" +rust_util = "0.2.3" diff --git a/src/build_json.rs b/src/build_json.rs index fcade9f..220d86b 100644 --- a/src/build_json.rs +++ b/src/build_json.rs @@ -5,8 +5,10 @@ use rust_util::{ XResult, new_box_ioerror, util_msg::{ - print_message, - MessageType, + print_ok, + print_debug, + print_warn, + print_error, } }; @@ -19,7 +21,7 @@ const GET_ARCHIVER_VERSION_URL: &str= "https://hatter.ink/repo/archive_info_vers pub fn get_archive_version(gid: &str, aid: &str) -> XResult { if *VERBOSE { - print_message(MessageType::DEBUG, &format!("Start get archive info: {}:{}", gid, aid)); + print_debug(&format!("Start get archive info: {}:{}", gid, aid)); } let mut url = String::with_capacity(1024); url.push_str(GET_ARCHIVER_VERSION_URL); @@ -29,7 +31,7 @@ pub fn get_archive_version(gid: &str, aid: &str) -> XResult { url.push_str(&urlencoding::encode(aid)); let version_result = get_url_content(url.as_str())?; if *VERBOSE { - print_message(MessageType::DEBUG, &format!("Get archive result: {}", version_result)); + print_debug(&format!("Get archive result: {}", version_result)); } let version_result_object = json::parse(&version_result)?; if version_result_object["status"] != 200 { @@ -41,7 +43,7 @@ pub fn get_archive_version(gid: &str, aid: &str) -> XResult { pub fn create_build_json(args: &[String]) { if find_build_json_in_current().is_some() { - print_message(MessageType::ERROR, &format!("File exits: {}", BUILD_JSON)); + print_error(&format!("File exits: {}", BUILD_JSON)); return; } @@ -60,7 +62,7 @@ pub fn create_build_json(args: &[String]) { } } if java_version.is_empty() || builder.is_empty() || builder_version.is_empty() { - print_message(MessageType::ERROR, "Args java version, builder or builder version is not assigned or format error."); + print_error("Args java version, builder or builder version is not assigned or format error."); return; } let mut build_json_object = object!{ @@ -71,7 +73,7 @@ pub fn create_build_json(args: &[String]) { }, }; match get_archive_version("me.hatter", "commons") { - Err(err) => print_message(MessageType::ERROR, &format!("Get me.hatter:commons version failed: {}", err)), + Err(err) => print_error(&format!("Get me.hatter:commons version failed: {}", err)), Ok(ver) => build_json_object["repo"] = object! { "dependencies" => array! [ format!("me.hatter:commons:{}", ver).as_str() @@ -79,8 +81,8 @@ pub fn create_build_json(args: &[String]) { }, } match fs::write(BUILD_JSON, json::stringify_pretty(build_json_object, 4)) { - Ok(_) => print_message(MessageType::OK, &format!("Write file success: {}", BUILD_JSON)), - Err(err) => print_message(MessageType::ERROR, &format!("Write file failed: {}, error message: {}", BUILD_JSON, err)), + Ok(_) => print_ok(&format!("Write file success: {}", BUILD_JSON)), + Err(err) => print_error(&format!("Write file failed: {}, error message: {}", BUILD_JSON, err)), } } @@ -97,7 +99,7 @@ pub fn find_build_json_in_parents() -> Option { loop { loop_count += 1_usize; if loop_count > 100_usize { - print_message(MessageType::ERROR, "Find build.json loop more than 100 loop!"); + print_error("Find build.json loop more than 100 loop!"); return None; } @@ -119,11 +121,11 @@ pub fn find_build_json() -> Option { Some(p) => Some(p), None => match find_build_json_in_parents() { Some(p) => { - print_message(MessageType::WARN, &format!("Cannot find {} in current dir, find: {}", BUILD_JSON, p)); + print_warn(&format!("Cannot find {} in current dir, find: {}", BUILD_JSON, p)); Some(p) }, None => { - print_message(MessageType::ERROR, &format!("Cannot find {}", BUILD_JSON)); + print_error(&format!("Cannot find {}", BUILD_JSON)); None }, },