Skip to content

Commit

Permalink
Allow using --type-list without pattern and replacement
Browse files Browse the repository at this point in the history
Fix #100
  • Loading branch information
dmerejkowsky committed Sep 22, 2022
1 parent 727a1b4 commit 28a7fc6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
32 changes: 19 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 @@ -16,7 +16,7 @@ extended-description = "Find and replace text in source files"
[dependencies]
anyhow = "1.0.32"
atty = "0.2.14"
clap = { version = "3.0.7", features = ["derive"] }
clap = { version = "3.2.22", features = ["derive"] }
colored = "2.0"
ignore = "0.4"
Inflector = "0.11"
Expand Down
28 changes: 21 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,29 @@ fn on_type_list() {
}

pub fn run() -> Result<()> {
let opt = Options::parse();
// PATTERN and REPLACEMENT are always required, except
// when --type-list is used
//
// So we cach the ErrorKind::MissingRequiredArgument error
// to handle the exception, rather than having the usage
// looking like `ruplacer [OPTIONS]`
let mut args = std::env::args();
let parsed = Options::try_parse();
let opt = match parsed {
Ok(o) => o,
Err(e) => {
let used_typed_list = args.any(|x| &x == "--type-list");
if used_typed_list {
on_type_list();
return Ok(());
} else {
e.exit();
}
}
};
let Options {
color_when,
file_type_list,
file_type_list: _,
go,
quiet,
hidden,
Expand All @@ -184,11 +203,6 @@ pub fn run() -> Result<()> {
word_regex,
} = opt;

if file_type_list {
on_type_list();
return Ok(());
}

let dry_run = !go;
let verbosity = if quiet {
Verbosity::Quiet
Expand Down

0 comments on commit 28a7fc6

Please sign in to comment.