diff --git a/README.md b/README.md index 72b177f..2e36fcc 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +Because this project scratches my particular itch and allows me to try/learn rust. diff --git a/src/lib.rs b/src/lib.rs index 61a6520..76e3790 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ pub enum RenameCommand { FixExtension(bool), Normalize, Replace(String, String, bool), - ChangeCase, + ChangeCase(bool), } pub struct Config { @@ -141,9 +141,12 @@ fn suggest_renames(files: &[PathBuf], command: &RenameCommand) -> Vec { + 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), diff --git a/src/main.rs b/src/main.rs index 89f5489..1535a5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,9 @@ fn extract_command(args_matches: &ArgMatches) -> Option { matches.get_one::("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, } } @@ -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), @@ -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), + ), ) }