mirror of
https://github.com/jht5945/finding.git
synced 2025-12-29 22:20:05 +08:00
move parse_size to opt.rs
This commit is contained in:
@@ -293,17 +293,13 @@ fn find_text_files(options: &Options, dir_path: &Path) {
|
||||
|
||||
fn main() -> XResult<()> {
|
||||
let mut options = Options::new();
|
||||
options.parse_args();
|
||||
options.parse_args().ok();
|
||||
|
||||
if options.version {
|
||||
print_version();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
options.parsed_huge_file_size = parse_size(&options.huge_file_size)? as u64;
|
||||
options.parsed_large_text_file_size = parse_size(&options.large_text_file_size)? as u64;
|
||||
options.parsed_large_line_size = parse_size(&options.large_line_size)? as u64;
|
||||
|
||||
let dir_path = match get_absolute_path(&options.dir) {
|
||||
None => {
|
||||
return Err(new_box_error(&format!("Cannot find dir: {}", options.dir)));
|
||||
|
||||
11
src/opt.rs
11
src/opt.rs
@@ -1,6 +1,8 @@
|
||||
|
||||
use argparse::{ArgumentParser, StoreTrue, Store};
|
||||
|
||||
use rust_util::*;
|
||||
|
||||
pub struct Options {
|
||||
pub version: bool,
|
||||
pub target: String,
|
||||
@@ -42,7 +44,8 @@ impl Options {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_args(&mut self) {
|
||||
pub fn parse_args(&mut self) -> XResult<()> {
|
||||
{
|
||||
let mut ap = ArgumentParser::new();
|
||||
ap.set_description("finding - command line find tool.");
|
||||
ap.refer(&mut self.target).add_option(&["-t", "--target"], Store, "Target, text, huge[file], default text");
|
||||
@@ -60,4 +63,10 @@ impl Options {
|
||||
ap.refer(&mut self.search_text).add_argument("SEARCH TEXT", Store, "Search text");
|
||||
ap.parse_args_or_exit();
|
||||
}
|
||||
|
||||
self.parsed_huge_file_size = parse_size(&self.huge_file_size)? as u64;
|
||||
self.parsed_large_text_file_size = parse_size(&self.large_text_file_size)? as u64;
|
||||
self.parsed_large_line_size = parse_size(&self.large_line_size)? as u64;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user