Skip to content

Commit

Permalink
change-case --upper
Browse files Browse the repository at this point in the history
  • Loading branch information
janpipek committed Sep 4, 2024
1 parent 3ad3d4f commit e7a1475
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 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.
9 changes: 6 additions & 3 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 @@ -141,9 +141,12 @@ fn suggest_renames(files: &[PathBuf], command: &RenameCommand) -> Vec<RenameInte
new_name: PathBuf::from(new_name),
}
}
RenameCommand::ChangeCase => {
RenameCommand::ChangeCase(upper) => {
let path_str = path.to_string_lossy().to_string();
let new_name = path_str.to_lowercase();
let new_name = match upper {
true => path_str.to_uppercase(),
false => path_str.to_lowercase(),
};
RenameIntent {
path: path.clone(),
new_name: PathBuf::from(new_name),
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 e7a1475

Please sign in to comment.