1
0
mirror of https://github.com/jht5945/buildj.git synced 2025-12-29 10:20:04 +08:00

update verbose

This commit is contained in:
2019-08-09 00:21:19 +08:00
parent 9b504d255e
commit 9bcff398a4
6 changed files with 31 additions and 8 deletions

1
Cargo.lock generated
View File

@@ -80,6 +80,7 @@ version = "0.1.2"
dependencies = [ dependencies = [
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"json 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)", "json 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.19 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.19 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (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.1.0 (git+https://github.com/jht5945/rust_util)", "rust_util 0.1.0 (git+https://github.com/jht5945/rust_util)",

View File

@@ -11,4 +11,5 @@ reqwest = "0.9.18"
urlencoding = "1.0.0" urlencoding = "1.0.0"
dirs = "2.0.1" dirs = "2.0.1"
rust-crypto = "0.2.36" rust-crypto = "0.2.36"
lazy_static = "1.3.0"
rust_util = { git = "https://github.com/jht5945/rust_util" } rust_util = { git = "https://github.com/jht5945/rust_util" }

View File

@@ -3,4 +3,7 @@ fn main() {
let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap(); let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap(); let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash); println!("cargo:rustc-env=GIT_HASH={}", git_hash);
let date_output = Command::new("date").output().unwrap();
let date = String::from_utf8(date_output.stdout).unwrap();
println!("cargo:rustc-env=BUILD_DATE={}", date);
} }

View File

@@ -11,11 +11,12 @@ use rust_util::{
XResult, XResult,
}; };
use super::misc::*; use super::misc::{
VERBOSE,
};
pub fn download_url(url: &str, dest: &mut File) -> XResult<()> { pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
let verbose = is_verbose(); if *VERBOSE {
if verbose {
print_message(MessageType::DEBUG, &format!("Download URL: {}", url)); print_message(MessageType::DEBUG, &format!("Download URL: {}", url));
} }
let mut response = reqwest::get(url)?; let mut response = reqwest::get(url)?;
@@ -23,7 +24,7 @@ pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
None => -1, None => -1,
Some(len_value) => len_value.to_str().unwrap().parse::<i64>().unwrap(), Some(len_value) => len_value.to_str().unwrap().parse::<i64>().unwrap(),
}; };
if verbose { if *VERBOSE {
print_message(MessageType::DEBUG, &format!("Content-Length: {}", header_content_length)); print_message(MessageType::DEBUG, &format!("Content-Length: {}", header_content_length));
} }
copy_io(&mut response, dest, header_content_length)?; copy_io(&mut response, dest, header_content_length)?;
@@ -31,7 +32,7 @@ pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
} }
pub fn get_url(url: &str) -> XResult<String> { pub fn get_url(url: &str) -> XResult<String> {
if is_verbose() { if *VERBOSE {
print_message(MessageType::DEBUG, &format!("Get URL: {}", url)); print_message(MessageType::DEBUG, &format!("Get URL: {}", url));
} }
Ok(reqwest::get(url)?.text()?) Ok(reqwest::get(url)?.text()?)

View File

@@ -5,6 +5,8 @@ extern crate dirs;
extern crate crypto; extern crate crypto;
extern crate urlencoding; extern crate urlencoding;
extern crate rust_util; extern crate rust_util;
#[macro_use]
extern crate lazy_static;
pub mod jdk; pub mod jdk;
pub mod local_util; pub mod local_util;
@@ -33,6 +35,7 @@ use misc::*;
const BUILDJ: &str = "buildj"; const BUILDJ: &str = "buildj";
const BUDERJ_VER: &str = env!("CARGO_PKG_VERSION"); const BUDERJ_VER: &str = env!("CARGO_PKG_VERSION");
const GIT_HASH: &str = env!("GIT_HASH"); const GIT_HASH: &str = env!("GIT_HASH");
const BUILD_DATE: &str = env!("BUILD_DATE");
fn do_with_buildin_arg_java(first_arg: &str, args: &Vec<String>) { fn do_with_buildin_arg_java(first_arg: &str, args: &Vec<String>) {
@@ -137,6 +140,11 @@ fn do_with_buildin_args(args: &Vec<String>) {
fn main() { fn main() {
print_message(MessageType::INFO, &format!("{} - version {} - {}", BUILDJ, BUDERJ_VER, &GIT_HASH[0..7])); print_message(MessageType::INFO, &format!("{} - version {} - {}", BUILDJ, BUDERJ_VER, &GIT_HASH[0..7]));
if *VERBOSE {
print_message(MessageType::DEBUG, &format!("Full GIT_HASH: {}", GIT_HASH));
print_message(MessageType::DEBUG, &format!("Binary build date: {}", BUILD_DATE));
}
let args = local_util::get_args_as_vec(); let args = local_util::get_args_as_vec();
print_message(MessageType::INFO, &format!("Arguments: {:?}", args)); print_message(MessageType::INFO, &format!("Arguments: {:?}", args));

View File

@@ -1,15 +1,24 @@
use std::env; use std::env;
lazy_static! {
pub static ref VERBOSE: bool = is_verbose();
}
pub fn print_usage() { pub fn print_usage() {
print!(r#" print!(r#"
buildj ::: - print this message buildj ::: - print this message
buildj :::help - print this message buildj :::help - print this message
buildj :::create --java<version> --maven<version> - create java-version, maven-version project buildj :::create --java<version> --maven<version> - create java-version, maven-version project
e.g. buildj :::create --java1.8 --maven3.5.2
buildj :::create --java<version> --gradle<version> - create java-version, gradle-version project buildj :::create --java<version> --gradle<version> - create java-version, gradle-version project
buildj :::java<version> [-version] - run java with assigned version, e.g. buildj :::java1.8 -version e.g. buildj :::create --java1.8 --gradle3.5.1
buildj :::maven<version> [--java<version>] - run maven with assigned version and java version, e.g. buildj :::maven3.5.2 --java1.8 ARGS buildj :::java<version> [-version] - run java with assigned version
buildj :::gradle<version> [--java<version>] - run gradle with assigned version and java version, e.g. buildj :::gradle3.5.1 --java1.8 ARGS e.g. buildj :::java1.8 -version
buildj :::maven<version> [--java<version>] - run maven with assigned version and java version
e.g. buildj :::maven3.5.2 --java1.8 ARGS
buildj :::gradle<version> [--java<version>] - run gradle with assigned version and java version
e.g. buildj :::gradle3.5.1 --java1.8 ARGS
buildj - run build, run assigned version builder tool buildj - run build, run assigned version builder tool
"#); "#);
} }