1
0
mirror of https://github.com/jht5945/buildj.git synced 2025-12-27 17:20:06 +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> {
let path = fs::canonicalize(".").ok()?;
let p_build_json = &format!("{}/{}", path.to_str()?, BUILD_JSON);
let path_build_json = Path::new(p_build_json);
iff!(path_build_json.exists(), Some(p_build_json.to_string()), None)
let p_build_json = format!("{}/{}", path.to_str()?, BUILD_JSON);
let path_build_json = Path::new(&p_build_json);
iff!(path_build_json.exists(), Some(p_build_json), None)
}
pub fn find_build_json_in_parents() -> Option<String> {
@@ -104,10 +104,10 @@ pub fn find_build_json_in_parents() -> Option<String> {
if p == "/" {
return None;
}
let p_build_json = &format!("{}/{}", p, BUILD_JSON);
let path_build_json = Path::new(p_build_json);
let p_build_json = format!("{}/{}", p, BUILD_JSON);
let path_build_json = Path::new(&p_build_json);
if path_build_json.exists() {
return Some(p_build_json.to_string());
return Some(p_build_json);
}
path = path.parent()?.to_path_buf();
}

View File

@@ -1,12 +1,12 @@
use std::fs::File;
use rust_util::{
XResult,
util_io::copy_io,
util_msg::{
print_message,
MessageType,
},
XResult,
};
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 header_content_length: i64 = match response.headers().get("content-length") {
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 {
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 {
match args.get(1) {
None => return false,
None => false,
Some(arg) => arg.starts_with(":::") || arg.starts_with("..."),
}
}

View File

@@ -22,6 +22,7 @@ use std::{
};
use rust_util::{
iff,
util_msg::{
print_message,
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());
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) {
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() {
println!(r#"buildj {} - {}
Copyright (C) 2019 Hatter Jiang.
Copyright (C) 2019-2020 Hatter Jiang.
License MIT <https://opensource.org/licenses/MIT>
Written by Hatter Jiang"#, super::BUDERJ_VER, &super::GIT_HASH[0..7]);