mirror of
https://github.com/jht5945/buildj.git
synced 2025-12-29 02:10:04 +08:00
ref print_*
This commit is contained in:
@@ -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<String> {
|
||||
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<String> {
|
||||
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<String> {
|
||||
|
||||
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<String> {
|
||||
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<String> {
|
||||
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
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user