Skip to content

Commit

Permalink
Merge pull request #14 from janpipek/change-case
Browse files Browse the repository at this point in the history
change-case --upper
  • Loading branch information
janpipek authored Sep 4, 2024
2 parents 59765e5 + 2f2c42a commit 2c10d45
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
# muren(mu)ltiple (ren)ames

Command-line utility for filename manipulations.

```
Usage: muren [OPTIONS] [COMMAND]
Commands:
set-ext Change extension
prefix Prefix with string
replace Replace parts of the name
normalize Convert names to reasonable ASCII.
fix-ext Fix extension according to the file contents.
remove Remove part of a name from all files.
help Print this message or the help of the given subcommand(s)
set-ext Change extension
prefix Prefix with string
replace Replace parts of the name
normalize Convert names to reasonable ASCII.
fix-ext Fix extension according to the file contents.
remove Remove part of a name from all files.
change-case Change case of all files.
help Print this message or the help of the given subcommand(s)
Options:
-d, --dry Dry run
-y, --yes Automatically confirm all actions
-h, --help Print help
-V, --version Print version
-d, --dry Dry run
-u, --unchanged Show unchanged files
-y, --yes Automatically confirm all actions
-h, --help Print help
-V, --version Print version
```

## Why not [rnr](https://github.com/ismaelgv/rnr)?

Because this project scratches my particular itch and allows me to try/learn rust.
Because this project scratches my particular itch and allows me to try/learn rust.
15 changes: 9 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub enum RenameCommand {
FixExtension(bool),
Normalize,
Replace(String, String, bool),
ChangeCase,
ChangeCase(bool),
}

pub struct Config {
Expand Down Expand Up @@ -85,6 +85,14 @@ fn suggest_renames(files: &[PathBuf], command: &RenameCommand) -> Vec<RenameInte
let new_name = path.to_string_lossy().replace(pattern, "");
PathBuf::from(new_name)
}
RenameCommand::ChangeCase(upper) => {
let path_str = path.to_string_lossy().to_string();
let new_name = match upper {
true => path_str.to_uppercase(),
false => path_str.to_lowercase(),
};
PathBuf::from(new_name)
}
RenameCommand::Prefix(prefix) => {
let mut new_name = prefix.clone();
new_name.push_str(path.to_string_lossy().to_string().as_str());
Expand Down Expand Up @@ -121,11 +129,6 @@ fn suggest_renames(files: &[PathBuf], command: &RenameCommand) -> Vec<RenameInte
};
PathBuf::from(new_name)
}
RenameCommand::ChangeCase => {
let path_str = path.to_string_lossy().to_string();
let new_name = path_str.to_lowercase();
PathBuf::from(new_name)
}
}}
)
.collect()
Expand Down
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ fn extract_command(args_matches: &ArgMatches) -> Option<RenameCommand> {
matches.get_one::<String>("replacement").unwrap().clone(),
matches.get_flag("regex"),
)),
Some(("change-case", _)) => Some(RenameCommand::ChangeCase),
Some(("change-case", matches)) => {
Some(RenameCommand::ChangeCase(matches.get_flag("upper")))
}
_ => None,
}
}
Expand Down Expand Up @@ -142,7 +144,7 @@ fn create_cli_command() -> Command {
.about("Remove part of a name from all files.")
.arg(
Arg::new("pattern")
.help("The string to remove")
.help("The string to remove.")
.action(ArgAction::Set)
.value_parser(value_parser!(String))
.required(true),
Expand All @@ -152,7 +154,13 @@ fn create_cli_command() -> Command {
.subcommand(
Command::new("change-case")
.about("Change case of all files.")
.arg(path_arg.clone()),
.arg(path_arg.clone())
.arg(
arg!(
-u --upper ... "Upper case (default: false)."
)
.action(clap::ArgAction::SetTrue),
),
)
}

Expand Down

0 comments on commit 2c10d45

Please sign in to comment.