mirror of
https://github.com/jht5945/buildj.git
synced 2025-12-27 17:20:06 +08:00
style: use rust_util s macros
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -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.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rust_util 0.6.1 (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.3"
|
||||
version = "0.6.1"
|
||||
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.3 (registry+https://github.com/rust-lang/crates.io-index)" = "454c4fd8ae19dd245bdc073cb297e222362adf938c3e6f0c2f8ea1abc7be2fd0"
|
||||
"checksum rust_util 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fedaf744d95f50bb12bc754c5143005bb588eb0cdc125f0e1412e04185f6ec31"
|
||||
"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"
|
||||
|
||||
@@ -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.3"
|
||||
rust_util = "0.6.1"
|
||||
|
||||
@@ -4,12 +4,6 @@ use rust_util::{
|
||||
iff,
|
||||
XResult,
|
||||
new_box_ioerror,
|
||||
util_msg::{
|
||||
print_ok,
|
||||
print_debug,
|
||||
print_warn,
|
||||
print_error,
|
||||
}
|
||||
};
|
||||
|
||||
use super::http::get_url_content;
|
||||
@@ -21,7 +15,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_debug(&format!("Start get archive info: {}:{}", gid, aid));
|
||||
debugging!("Start get archive info: {}:{}", gid, aid);
|
||||
}
|
||||
let mut url = String::with_capacity(1024);
|
||||
url.push_str(GET_ARCHIVER_VERSION_URL);
|
||||
@@ -31,7 +25,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_debug(&format!("Get archive result: {}", version_result));
|
||||
debugging!("Get archive result: {}", version_result);
|
||||
}
|
||||
let version_result_object = json::parse(&version_result)?;
|
||||
if version_result_object["status"] != 200 {
|
||||
@@ -43,7 +37,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_error(&format!("File exits: {}", BUILD_JSON));
|
||||
failure!("File exits: {}", BUILD_JSON);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,7 +56,7 @@ pub fn create_build_json(args: &[String]) {
|
||||
}
|
||||
}
|
||||
if java_version.is_empty() || builder.is_empty() || builder_version.is_empty() {
|
||||
print_error("Args java version, builder or builder version is not assigned or format error.");
|
||||
failure!("Args java version, builder or builder version is not assigned or format error.");
|
||||
return;
|
||||
}
|
||||
let mut build_json_object = object!{
|
||||
@@ -73,7 +67,7 @@ pub fn create_build_json(args: &[String]) {
|
||||
},
|
||||
};
|
||||
match get_archive_version("me.hatter", "commons") {
|
||||
Err(err) => print_error(&format!("Get me.hatter:commons version failed: {}", err)),
|
||||
Err(err) => failure!("Get me.hatter:commons version failed: {}", err),
|
||||
Ok(ver) => build_json_object["repo"] = object! {
|
||||
"dependencies" => array! [
|
||||
format!("me.hatter:commons:{}", ver).as_str()
|
||||
@@ -81,8 +75,8 @@ pub fn create_build_json(args: &[String]) {
|
||||
},
|
||||
}
|
||||
match fs::write(BUILD_JSON, json::stringify_pretty(build_json_object, 4)) {
|
||||
Ok(_) => print_ok(&format!("Write file success: {}", BUILD_JSON)),
|
||||
Err(err) => print_error(&format!("Write file failed: {}, error message: {}", BUILD_JSON, err)),
|
||||
Ok(_) => success!("Write file success: {}", BUILD_JSON),
|
||||
Err(err) => failure!("Write file failed: {}, error message: {}", BUILD_JSON, err),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +93,7 @@ pub fn find_build_json_in_parents() -> Option<String> {
|
||||
loop {
|
||||
loop_count += 1_usize;
|
||||
if loop_count > 100_usize {
|
||||
print_error("Find build.json loop more than 100 loop!");
|
||||
failure!("Find build.json loop more than 100 loop!");
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -121,11 +115,11 @@ pub fn find_build_json() -> Option<String> {
|
||||
Some(p) => Some(p),
|
||||
None => match find_build_json_in_parents() {
|
||||
Some(p) => {
|
||||
print_warn(&format!("Cannot find {} in current dir, find: {}", BUILD_JSON, p));
|
||||
warning!("Cannot find {} in current dir, find: {}", BUILD_JSON, p);
|
||||
Some(p)
|
||||
},
|
||||
None => {
|
||||
print_error(&format!("Cannot find {}", BUILD_JSON));
|
||||
failure!("Cannot find {}", BUILD_JSON);
|
||||
None
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{
|
||||
env,
|
||||
fs::{self, File},
|
||||
io::{Read, ErrorKind},
|
||||
fs::{ self, File },
|
||||
io::{ Read, ErrorKind },
|
||||
path::Path,
|
||||
process::Command,
|
||||
time::SystemTime,
|
||||
@@ -10,9 +10,7 @@ use std::{
|
||||
use rust_util::{
|
||||
XResult,
|
||||
new_box_ioerror,
|
||||
util_msg::{
|
||||
print_error,
|
||||
},
|
||||
util_msg::print_error,
|
||||
util_io::*,
|
||||
};
|
||||
|
||||
@@ -81,7 +79,7 @@ pub fn calc_file_digest(digest: &mut dyn Digest, digest_alg: &str, file_name: &s
|
||||
};
|
||||
digest.input(&buf[..len]);
|
||||
written += len as i64;
|
||||
let cost = SystemTime::now().duration_since(start.clone()).unwrap();
|
||||
let cost = SystemTime::now().duration_since(start).unwrap();
|
||||
print_status_last_line(&format!("Calc {}", digest_alg), file_len, written, cost);
|
||||
}
|
||||
}
|
||||
|
||||
21
src/main.rs
21
src/main.rs
@@ -6,6 +6,7 @@ extern crate term;
|
||||
extern crate dirs;
|
||||
extern crate crypto;
|
||||
extern crate urlencoding;
|
||||
#[macro_use]
|
||||
extern crate rust_util;
|
||||
|
||||
pub mod jdk;
|
||||
@@ -46,13 +47,13 @@ const BUILD_DATE: &str = env!("BUILD_DATE");
|
||||
fn do_with_buildin_arg_java(first_arg: &str, args: &[String]) {
|
||||
let ver = &first_arg[7..];
|
||||
if ver.is_empty() {
|
||||
print_error("Java version is not assigned!");
|
||||
failure!("Java version is not assigned!");
|
||||
return;
|
||||
}
|
||||
match get_java_home(ver) {
|
||||
None => print_error(&format!("Assigned java version not found: {}", ver)),
|
||||
None => failure!("Assigned java version not found: {}", ver),
|
||||
Some(java_home) => {
|
||||
print_ok(&format!("Find java home: {}", java_home));
|
||||
success!("Find java home: {}", java_home);
|
||||
let java_bin = &format!("{}/bin/java", java_home);
|
||||
let mut cmd = Command::new(java_bin);
|
||||
cmd.envs(&get_env_with_java_home(&java_home));
|
||||
@@ -60,7 +61,7 @@ fn do_with_buildin_arg_java(first_arg: &str, args: &[String]) {
|
||||
cmd.args(&args[2..]);
|
||||
}
|
||||
run_command_and_wait(&mut cmd).unwrap_or_else(|err| {
|
||||
print_error(&format!("Exec java failed: {}", err));
|
||||
failure!("Exec java failed: {}", err);
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -76,13 +77,13 @@ fn do_with_buildin_arg_gradle(first_arg: &str, args: &[String]) {
|
||||
|
||||
fn do_with_buildin_arg_config(_first_arg: &str, args: &[String]) {
|
||||
if args.len() <= 2 {
|
||||
print_error("No arguments, get or set.");
|
||||
failure!("No arguments, get or set.");
|
||||
return;
|
||||
}
|
||||
match args[2].as_str() {
|
||||
"get" => match get_tool_package_secret() {
|
||||
Err(_) => print_warn("No config found."),
|
||||
Ok(secret) => print_ok(&format!("Config secret: {}", secret)),
|
||||
Err(_) => warning!("No config found."),
|
||||
Ok(secret) => success!("Config secret: {}", secret),
|
||||
},
|
||||
"set" => {
|
||||
if args.len() < 4 {
|
||||
@@ -345,11 +346,11 @@ fn read_build_json_object() -> Option<json::JsonValue> {
|
||||
|
||||
|
||||
fn main() {
|
||||
print_info(&format!("{} - version {} - {}", BUILDJ, BUDERJ_VER, &GIT_HASH[0..7]));
|
||||
information!("{} - version {} - {}", BUILDJ, BUDERJ_VER, &GIT_HASH[0..7]);
|
||||
|
||||
if *VERBOSE {
|
||||
print_debug(&format!("Full GIT_HASH: {}", GIT_HASH));
|
||||
print_debug(&format!("Build date: {}", BUILD_DATE));
|
||||
debugging!("Full GIT_HASH: {}", GIT_HASH);
|
||||
debugging!("Build date: {}", BUILD_DATE);
|
||||
}
|
||||
|
||||
let args = local_util::get_args_as_vec();
|
||||
|
||||
Reference in New Issue
Block a user