1
0
mirror of https://github.com/jht5945/buildj.git synced 2025-12-30 02:40:03 +08:00
This commit is contained in:
2020-05-02 14:51:59 +08:00
parent 0667b3d481
commit dc116799e0
5 changed files with 25 additions and 11 deletions

View File

@@ -85,9 +85,9 @@ pub fn create_build_json(args: &[String]) {
pub fn find_build_json_in_current() -> Option<String> { pub fn find_build_json_in_current() -> Option<String> {
let path = fs::canonicalize(".").ok()?; let path = fs::canonicalize(".").ok()?;
let p_build_json = &format!("{}/{}", path.to_str()?, BUILD_JSON); let p_build_json = format!("{}/{}", path.to_str()?, BUILD_JSON);
let path_build_json = Path::new(p_build_json); let path_build_json = Path::new(&p_build_json);
iff!(path_build_json.exists(), Some(p_build_json.to_string()), None) iff!(path_build_json.exists(), Some(p_build_json), None)
} }
pub fn find_build_json_in_parents() -> Option<String> { pub fn find_build_json_in_parents() -> Option<String> {
@@ -104,10 +104,10 @@ pub fn find_build_json_in_parents() -> Option<String> {
if p == "/" { if p == "/" {
return None; return None;
} }
let p_build_json = &format!("{}/{}", p, BUILD_JSON); let p_build_json = format!("{}/{}", p, BUILD_JSON);
let path_build_json = Path::new(p_build_json); let path_build_json = Path::new(&p_build_json);
if path_build_json.exists() { if path_build_json.exists() {
return Some(p_build_json.to_string()); return Some(p_build_json);
} }
path = path.parent()?.to_path_buf(); path = path.parent()?.to_path_buf();
} }

View File

@@ -1,12 +1,12 @@
use std::fs::File; use std::fs::File;
use rust_util::{ use rust_util::{
XResult,
util_io::copy_io, util_io::copy_io,
util_msg::{ util_msg::{
print_message, print_message,
MessageType, MessageType,
}, },
XResult,
}; };
use super::misc::VERBOSE; use super::misc::VERBOSE;
@@ -18,7 +18,20 @@ pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
let mut response = reqwest::get(url)?; let mut response = reqwest::get(url)?;
let header_content_length: i64 = match response.headers().get("content-length") { let header_content_length: i64 = match response.headers().get("content-length") {
None => -1_i64, None => -1_i64,
Some(len_value) => len_value.to_str().unwrap().parse::<i64>().unwrap(), Some(len_value) => {
let len_str = match len_value.to_str() {
Ok(len_str) => len_str, Err(err) => {
print_message(MessageType::WARN, &format!("Get content length for {:?}, error: {}", len_value, err));
"-1"
},
};
match len_str.parse::<i64>() {
Ok(len) => len, Err(err) => {
print_message(MessageType::WARN, &format!("Get content length for {:?}, error: {}", len_value, err));
-1
}
}
},
}; };
if *VERBOSE { if *VERBOSE {
print_message(MessageType::DEBUG, &format!("Content-Length: {}", header_content_length)); print_message(MessageType::DEBUG, &format!("Content-Length: {}", header_content_length));

View File

@@ -34,7 +34,7 @@ pub fn get_args_as_vec() -> Vec<String> {
pub fn is_buildin_args(args: &[String]) -> bool { pub fn is_buildin_args(args: &[String]) -> bool {
match args.get(1) { match args.get(1) {
None => return false, None => false,
Some(arg) => arg.starts_with(":::") || arg.starts_with("..."), Some(arg) => arg.starts_with(":::") || arg.starts_with("..."),
} }
} }

View File

@@ -22,6 +22,7 @@ use std::{
}; };
use rust_util::{ use rust_util::{
iff,
util_msg::{ util_msg::{
print_message, print_message,
MessageType, MessageType,
@@ -136,7 +137,7 @@ fn do_with_buildin_arg_builder(first_arg: &str, args: &[String], builder_name: &
let mut cmd = Command::new(builder_desc.get_builder_bin()); let mut cmd = Command::new(builder_desc.get_builder_bin());
cmd.envs(&new_env); cmd.envs(&new_env);
let from_index = if has_java { 3 } else { 2 }; let from_index = iff!(has_java, 3, 2);
for arg in args.iter().skip(from_index) { for arg in args.iter().skip(from_index) {
cmd.arg(&arg); cmd.arg(&arg);
} }

View File

@@ -38,7 +38,7 @@ BUILDJ_JAVA=1.8 BUILDJ_BUILDER=maven3.5.2 buildj - direct run buildj"#);
pub fn print_version() { pub fn print_version() {
println!(r#"buildj {} - {} println!(r#"buildj {} - {}
Copyright (C) 2019 Hatter Jiang. Copyright (C) 2019-2020 Hatter Jiang.
License MIT <https://opensource.org/licenses/MIT> License MIT <https://opensource.org/licenses/MIT>
Written by Hatter Jiang"#, super::BUDERJ_VER, &super::GIT_HASH[0..7]); Written by Hatter Jiang"#, super::BUDERJ_VER, &super::GIT_HASH[0..7]);