Skip to content

Commit

Permalink
Update dependencies and remove context module
Browse files Browse the repository at this point in the history
  • Loading branch information
yaa110 committed Feb 24, 2021
1 parent b81910c commit 88ca0f6
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 57 deletions.
78 changes: 65 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
name = "nomino"
readme = "README.md"
repository = "https://github.com/yaa110/nomino"
version = "0.4.5"
version = "0.4.6"

[dependencies]
atty = "0.2"
Expand Down
28 changes: 0 additions & 28 deletions src/input/context.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/input/iterator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::errors::{FormatError, SourceError};
use crate::input::{Formatter, SortOrder, Source};
use natord;
use regex::Regex;
use std::error::Error;
use std::fs;
Expand Down
1 change: 0 additions & 1 deletion src/input/source.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::errors::SortOrderError;
use regex::Regex;
use serde_json;
use std::collections::HashMap;
use std::error::Error;
use std::fs;
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
pub mod input {
mod context;
mod formatter;
mod iterator;
mod source;
pub use self::context::*;
pub use self::formatter::*;
pub use self::iterator::*;
pub use self::source::*;
Expand Down
21 changes: 10 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use atty::Stream;
use clap::{load_yaml, App};
use colored::{self, Colorize};
use nomino::errors::SourceError;
use nomino::input::{Context, Formatter, Source};
use nomino::input::{Formatter, InputIterator, Source};
use prettytable::{cell, format, row, Table};
use serde_json::map::Map;
use serde_json::value::Value;
Expand Down Expand Up @@ -44,16 +44,16 @@ fn read_output(output: Option<&str>) -> Result<Option<Formatter>, Box<dyn Error>
}

fn rename_files(
context: Context,
input_iter: InputIterator,
test_mode: bool,
need_map: bool,
overwrite: bool,
mkdir: bool,
) -> Result<(Option<Map<String, Value>>, bool), Box<dyn Error>> {
) -> (Option<Map<String, Value>>, bool) {
let mut map = if need_map { Some(Map::new()) } else { None };
let mut is_renamed = true;
let mut with_err = false;
for (input, mut output) in context {
for (input, mut output) in input_iter {
let mut file_path_buf;
let mut file_path = Path::new(output.as_str());
if !overwrite {
Expand Down Expand Up @@ -97,10 +97,10 @@ fn rename_files(
}
is_renamed = true;
}
Ok((map, with_err))
(map, with_err)
}

fn print_map_table(map: Map<String, Value>) -> Result<(), Box<dyn Error>> {
fn print_map_table(map: Map<String, Value>) {
let mut table = Table::new();
table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
table.set_titles(row!["Input".cyan(), "Output".cyan()]);
Expand All @@ -116,7 +116,6 @@ fn print_map_table(map: Map<String, Value>) -> Result<(), Box<dyn Error>> {
}
});
table.printstd();
Ok(())
}

fn run_app() -> Result<bool, Box<dyn Error>> {
Expand All @@ -125,7 +124,7 @@ fn run_app() -> Result<bool, Box<dyn Error>> {
if let Some(cwd) = opts.value_of("directory").map(Path::new) {
set_current_dir(cwd)?;
}
let context = Context::new(
let input_iter = InputIterator::new(
read_source(
opts.value_of("regex"),
opts.value_of("sort"),
Expand All @@ -137,12 +136,12 @@ fn run_app() -> Result<bool, Box<dyn Error>> {
let print_map = opts.is_present("print");
let generate_map = opts.value_of("generate");
let (map, with_err) = rename_files(
context,
input_iter,
opts.is_present("test"),
print_map || generate_map.is_some(),
opts.is_present("overwrite"),
opts.is_present("mkdir"),
)?;
);
if let Some(map_file) = generate_map {
fs::write(
map_file,
Expand All @@ -151,7 +150,7 @@ fn run_app() -> Result<bool, Box<dyn Error>> {
}
if print_map && !map.as_ref().unwrap().is_empty() {
colored::control::set_override(atty::is(Stream::Stdout));
print_map_table(map.unwrap())?;
print_map_table(map.unwrap());
}
Ok(with_err)
}
Expand Down

0 comments on commit 88ca0f6

Please sign in to comment.