Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into refactorings2
Browse files Browse the repository at this point in the history
  • Loading branch information
janpipek committed Sep 4, 2024
2 parents 48af50b + 2c10d45 commit 0cf97d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum RenameCommand {
FixExtension(bool),
Normalize,
Replace(String, String, bool),
ChangeCase,
ChangeCase(bool),
}

pub struct Config {
Expand Down Expand Up @@ -122,9 +122,12 @@ fn suggest_rename(path: &PathBuf, command: &RenameCommand) -> RenameIntent {
};
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(),
};
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 0cf97d8

Please sign in to comment.