1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-27 15:40:03 +08:00

chore: uses

This commit is contained in:
2021-01-03 13:12:55 +08:00
parent aa8b4ed447
commit 50159a0ca8
9 changed files with 23 additions and 27 deletions

View File

@@ -1,13 +1,9 @@
#[macro_use] #[macro_use] extern crate lazy_static;
extern crate lazy_static;
extern crate term; extern crate term;
use std::error::Error; use std::error::Error;
use std::io::Error as IoError; use std::io::{Error as IoError, ErrorKind};
use std::io::ErrorKind; use std::fmt::{Display, Formatter, Result as FmtResult};
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
pub mod util_io; pub mod util_io;
pub mod util_os; pub mod util_os;

View File

@@ -1,7 +1,6 @@
use std::process; use std::process;
use clap::{App, Arg, ArgMatches}; use clap::{App, Arg, ArgMatches};
use crate::XResult; use crate::{XResult, util_msg};
use crate::util_msg;
pub type CommandError = XResult<Option<i32>>; pub type CommandError = XResult<Option<i32>>;

View File

@@ -1,4 +1,7 @@
use std::{ env, fs::{ self, File }, io::{ Lines, BufReader }, path::{ Path, PathBuf } }; use std::env;
use std::fs::{self, File};
use std::io::{Lines, BufReader};
use std::path::{Path, PathBuf};
use crate::{iff, util_os, util_io, util_msg, new_box_ioerror, XResult}; use crate::{iff, util_os, util_io, util_msg, new_box_ioerror, XResult};
pub struct JoinFilesReader { pub struct JoinFilesReader {

View File

@@ -1,7 +1,5 @@
use std::process::Command; use std::process::Command;
use crate::XResult; use crate::{XResult, util_msg, util_cmd};
use crate::util_msg;
use crate::util_cmd::run_command_and_wait;
const LANG: &str = "LANG"; const LANG: &str = "LANG";
const EN_US: &str = "en_US"; const EN_US: &str = "en_US";
@@ -59,7 +57,7 @@ pub fn git_push(working_dir: Option<&str>) {
let mut cmd = new_git_command(working_dir); let mut cmd = new_git_command(working_dir);
cmd.arg("push"); cmd.arg("push");
util_msg::print_info(&format!("Exec: {:?}", cmd)); util_msg::print_info(&format!("Exec: {:?}", cmd));
if let Err(e) = run_command_and_wait(&mut cmd) { if let Err(e) = util_cmd::run_command_and_wait(&mut cmd) {
util_msg::print_error(&format!("Run git push failed: {}", e)); util_msg::print_error(&format!("Run git push failed: {}", e));
} }
} }
@@ -71,7 +69,7 @@ pub fn git_add(working_dir: Option<&str>, files: &[String]) {
cmd.arg(&f); cmd.arg(&f);
} }
util_msg::print_info(&format!("Exec: {:?}", cmd)); util_msg::print_info(&format!("Exec: {:?}", cmd));
if let Err(e) = run_command_and_wait(&mut cmd) { if let Err(e) = util_cmd::run_command_and_wait(&mut cmd) {
util_msg::print_error(&format!("Run git add failed: {}", e)); util_msg::print_error(&format!("Run git add failed: {}", e));
} }
} }
@@ -85,7 +83,7 @@ pub fn git_commit(working_dir: Option<&str>, message: &str, files: &[String]) {
cmd.arg(&f); cmd.arg(&f);
} }
util_msg::print_info(&format!("Exec: {:?}", cmd)); util_msg::print_info(&format!("Exec: {:?}", cmd));
if let Err(e) = run_command_and_wait(&mut cmd) { if let Err(e) = util_cmd::run_command_and_wait(&mut cmd) {
util_msg::print_error(&format!("Run git commit failed: {}", e)); util_msg::print_error(&format!("Run git commit failed: {}", e));
} }
} }

View File

@@ -2,7 +2,7 @@ use std::io::{ self, Write, ErrorKind, prelude::* };
use std::fs::File; use std::fs::File;
use std::time::{SystemTime, Duration}; use std::time::{SystemTime, Duration};
use crate::{SimpleError, XResult, new_box_ioerror}; use crate::{SimpleError, XResult};
use crate::util_size; use crate::util_size;
use crate::util_msg; use crate::util_msg;
use crate::util_file; use crate::util_file;
@@ -86,7 +86,7 @@ pub fn get_read_stdin_or_file(file: &str) -> XResult<Box<dyn Read>> {
} else { } else {
match File::open(&util_file::resolve_file_path(file)) { match File::open(&util_file::resolve_file_path(file)) {
Ok(f) => Ok(Box::new(f)), Ok(f) => Ok(Box::new(f)),
Err(err) => Err(new_box_ioerror(&format!("Open file {}, erorr: {}", file, err))), Err(err) => Err(SimpleError::new(format!("Open file {}, erorr: {}", file, err)).into()),
} }
} }
} }

View File

@@ -1,4 +1,6 @@
use std::{ env, io::{ self, Write }, sync::{ Arc, Mutex } }; use std::env;
use std::io::{self, Write};
use std::sync::{Arc, Mutex};
lazy_static! { lazy_static! {
pub static ref IS_ATTY: bool = is_atty(); pub static ref IS_ATTY: bool = is_atty();

View File

@@ -1,5 +1,4 @@
use std::io; use std::io::{self, Write};
use std::io::Write;
pub const RED: &str = "\x1B[91m"; pub const RED: &str = "\x1B[91m";
pub const GREEN: &str = "\x1B[92m"; pub const GREEN: &str = "\x1B[92m";

View File

@@ -1,5 +1,4 @@
use std::time::SystemTime; use std::time::{SystemTime, Duration};
use std::time::Duration;
pub fn get_current_secs() -> u64 { pub fn get_current_secs() -> u64 {
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0 /* SHOULD NOT HAPPEN */ ) SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0 /* SHOULD NOT HAPPEN */ )