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:
10
src/lib.rs
10
src/lib.rs
@@ -1,13 +1,9 @@
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use] extern crate lazy_static;
|
||||
extern crate term;
|
||||
|
||||
use std::error::Error;
|
||||
use std::io::Error as IoError;
|
||||
use std::io::ErrorKind;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::Formatter;
|
||||
use std::fmt::Result as FmtResult;
|
||||
use std::io::{Error as IoError, ErrorKind};
|
||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||
|
||||
pub mod util_io;
|
||||
pub mod util_os;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::process;
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use crate::XResult;
|
||||
use crate::util_msg;
|
||||
use crate::{XResult, util_msg};
|
||||
|
||||
pub type CommandError = XResult<Option<i32>>;
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use std::{ env, fs::{ self, File }, io::{ Lines, BufReader }, path::{ Path, PathBuf } };
|
||||
use crate::{ iff, util_os, util_io, util_msg, new_box_ioerror, XResult };
|
||||
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};
|
||||
|
||||
pub struct JoinFilesReader {
|
||||
files: Vec<String>,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use std::process::Command;
|
||||
use crate::XResult;
|
||||
use crate::util_msg;
|
||||
use crate::util_cmd::run_command_and_wait;
|
||||
use crate::{XResult, util_msg, util_cmd};
|
||||
|
||||
const LANG: &str = "LANG";
|
||||
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);
|
||||
cmd.arg("push");
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -71,7 +69,7 @@ pub fn git_add(working_dir: Option<&str>, files: &[String]) {
|
||||
cmd.arg(&f);
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -85,7 +83,7 @@ pub fn git_commit(working_dir: Option<&str>, message: &str, files: &[String]) {
|
||||
cmd.arg(&f);
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::io::{ self, Write, ErrorKind, prelude::* };
|
||||
use std::io::{self, Write, ErrorKind, prelude::*};
|
||||
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_msg;
|
||||
use crate::util_file;
|
||||
@@ -86,7 +86,7 @@ pub fn get_read_stdin_or_file(file: &str) -> XResult<Box<dyn Read>> {
|
||||
} else {
|
||||
match File::open(&util_file::resolve_file_path(file)) {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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! {
|
||||
pub static ref IS_ATTY: bool = is_atty();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::fmt::{ self, Display, Formatter };
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::result::Result;
|
||||
use std::net::SocketAddr;
|
||||
use crate::XResult;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::io::{self, Write};
|
||||
|
||||
pub const RED: &str = "\x1B[91m";
|
||||
pub const GREEN: &str = "\x1B[92m";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::time::SystemTime;
|
||||
use std::time::Duration;
|
||||
use std::time::{SystemTime, Duration};
|
||||
|
||||
pub fn get_current_secs() -> u64 {
|
||||
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0 /* SHOULD NOT HAPPEN */ )
|
||||
|
||||
Reference in New Issue
Block a user