1
0
mirror of https://github.com/jht5945/finding.git synced 2025-12-29 22:20:05 +08:00

style: code style

This commit is contained in:
2020-08-02 22:30:48 +08:00
parent 6f274d9a46
commit bb8103dac9
3 changed files with 26 additions and 24 deletions

6
Cargo.lock generated
View File

@@ -130,7 +130,7 @@ name = "finding"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"argparse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "argparse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rust_util 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rust_util 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@@ -237,7 +237,7 @@ dependencies = [
[[package]] [[package]]
name = "rust_util" name = "rust_util"
version = "0.2.2" version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -357,7 +357,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecedbca3bf205f8d8f5c2b44d83cd0690e39ee84b951ed649e9f1841132b66d" "checksum redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecedbca3bf205f8d8f5c2b44d83cd0690e39ee84b951ed649e9f1841132b66d"
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf" "checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
"checksum rust_util 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd9973675144c03fdf6f9a559ea5c254b0008e90a8992b1f317f728edd3512bc" "checksum rust_util 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9e9cf201657d8553fd7eddf4c20e00b1bdebca40e9fa2ede5c87f6874d02750f"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238" "checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238"
"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"

View File

@@ -12,4 +12,4 @@ license = "MIT"
argparse = "0.2.2" argparse = "0.2.2"
term = "0.5.2" term = "0.5.2"
term_size = "0.3.1" term_size = "0.3.1"
rust_util = "0.2.2" rust_util = "0.6.3"

View File

@@ -1,6 +1,7 @@
extern crate argparse; extern crate argparse;
extern crate term; extern crate term;
extern crate term_size; extern crate term_size;
#[macro_use]
extern crate rust_util; extern crate rust_util;
mod opt; mod opt;
@@ -8,22 +9,23 @@ mod local_util;
use std::{ use std::{
path::Path, path::Path,
time::{ Duration, SystemTime,}, time::{ Duration, SystemTime },
}; };
use opt::*; use opt::*;
use rust_util::{ use rust_util::{
iff,
XResult, XResult,
new_box_error, new_box_error,
util_file::*, util_file::*,
util_size::*, util_size::*,
util_msg::*,
}; };
use local_util::{ use rust_util::util_msg::{
CountCell, MessageType,
MatchLine, print_color,
read_file_content, print_lastline,
print_message,
get_term_width_message,
}; };
use local_util::{ CountCell, MatchLine, read_file_content };
const EMPTY: &str = ""; const EMPTY: &str = "";
const VERSION: &str = env!("CARGO_PKG_VERSION"); const VERSION: &str = env!("CARGO_PKG_VERSION");
@@ -36,8 +38,8 @@ License MIT <https://opensource.org/licenses/MIT>
Written by Hatter Jiang"#, VERSION, &GIT_HASH[0..7]); Written by Hatter Jiang"#, VERSION, &GIT_HASH[0..7]);
if options.verbose { if options.verbose {
print_message(MessageType::DEBUG, &format!("Version: {}", VERSION)); debugging!("Version: {}", VERSION);
print_message(MessageType::DEBUG, &format!("Git hash: {}", GIT_HASH)); debugging!("Git hash: {}", GIT_HASH);
} }
} }
@@ -133,11 +135,11 @@ fn match_lines(tag: &str, content: &str, options: &Options) -> bool {
fn find_text_files(options: &Options, dir_path: &Path) { fn find_text_files(options: &Options, dir_path: &Path) {
if options.search_text.is_empty() { if options.search_text.is_empty() {
print_message(MessageType::ERROR, "Param search_text cannot be empty."); failure!("Param search_text cannot be empty.");
return; return;
} }
if options.ignore_case { if options.ignore_case {
print_message(MessageType::WARN, "Using ignore case mode, highlight print is disabled."); warning!("Using ignore case mode, highlight print is disabled.");
} }
let file_exts = match &options.file_ext { let file_exts = match &options.file_ext {
ext if ext.is_empty() => vec![], ext if ext.is_empty() => vec![],
@@ -195,13 +197,13 @@ fn find_text_files(options: &Options, dir_path: &Path) {
true true
}).ok(); }).ok();
print_lastline(EMPTY); print_lastline(EMPTY);
print_message(MessageType::OK, &format!("Total dir count: {}, scaned dir count: {}", success!("Total dir count: {}, scaned dir count: {}",
total_dir_count.get(), total_dir_count.get(),
scaned_dir_count.get())); scaned_dir_count.get());
print_message(MessageType::OK, &format!("Total file count: {}, scaned file count: {}, matched file count: {}", success!("Total file count: {}, scaned file count: {}, matched file count: {}",
total_file_count.get(), total_file_count.get(),
scaned_file_count.get(), scaned_file_count.get(),
matched_file_count.get())); matched_file_count.get());
} }
fn main() -> XResult<()> { fn main() -> XResult<()> {
@@ -222,7 +224,7 @@ fn main() -> XResult<()> {
"text" => find_text_files(&options, &dir_path), "text" => find_text_files(&options, &dir_path),
others => return Err(new_box_error(&format!("Unknown command: {}", others))), others => return Err(new_box_error(&format!("Unknown command: {}", others))),
} }
let cost_millis = SystemTime::now().duration_since(start.clone()).unwrap_or(Duration::from_millis(0)).as_millis(); let cost_millis = SystemTime::now().duration_since(start).unwrap_or_else(|_| Duration::from_millis(0)).as_millis();
print_message(MessageType::OK, &format!("Finding finished, cost {} ms", cost_millis)); success!("Finding finished, cost {} ms", cost_millis);
Ok(()) Ok(())
} }