-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b407335
commit 83bf1f7
Showing
7 changed files
with
86 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use clap_complete::generate_to; | ||
use clap_complete::shells::{Bash, Fish, Zsh}; | ||
use std::env; | ||
use std::ffi::OsString; | ||
use std::fs::{create_dir, remove_dir_all}; | ||
use std::io::Error; | ||
|
||
include!("src/args.rs"); | ||
|
||
fn main() -> Result<(), Error> { | ||
let target = "./target/autocomplete"; | ||
remove_dir_all(target).ok(); | ||
create_dir(target)?; | ||
let outdir = OsString::from(target); | ||
|
||
let mut cmd = get_command(); | ||
generate_to(Bash, &mut cmd, "movie-rename", &outdir)?; | ||
generate_to(Fish, &mut cmd, "movie-rename", &outdir)?; | ||
generate_to(Zsh, &mut cmd, "movie-rename", &outdir)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use clap::{arg, command, ArgAction, Command, ValueHint}; | ||
use std::collections::HashMap; | ||
|
||
// Bare command generation function to help with autocompletion | ||
pub fn get_command() -> Command { | ||
command!() | ||
.name("movie-rename") | ||
.author("Sayantan Santra <[email protected]>") | ||
.about("A simple tool to rename movies, written in Rust.") | ||
.arg(arg!(-d --directory "Run in directory mode").action(ArgAction::SetTrue)) | ||
.arg(arg!(-n --"dry-run" "Do a dry run").action(ArgAction::SetTrue)) | ||
.arg(arg!(-l --"i-feel-lucky" "Always choose the first option").action(ArgAction::SetTrue)) | ||
.arg( | ||
arg!([entries] "The files/directories to be processed") | ||
.trailing_var_arg(true) | ||
.num_args(1..) | ||
.value_hint(ValueHint::AnyPath) | ||
.required(true), | ||
) | ||
// Use -v instead of -V for version | ||
.disable_version_flag(true) | ||
.arg(arg!(-v --version "Print version").action(ArgAction::Version)) | ||
.arg_required_else_help(true) | ||
} | ||
|
||
// Function to process the passed arguments | ||
pub fn process_args() -> (Vec<String>, HashMap<String, bool>) { | ||
let matches = get_command().get_matches(); | ||
|
||
// Generate the settings HashMap from read flags | ||
let mut settings = HashMap::new(); | ||
for id in matches.ids().map(|x| x.as_str()) { | ||
if id != "entries" { | ||
settings.insert(id.to_string(), matches.get_flag(id)); | ||
} | ||
} | ||
|
||
// Every unmatched argument should be treated as a file entry | ||
let entries: Vec<String> = matches | ||
.get_many::<String>("entries") | ||
.expect("No entries provided!") | ||
.cloned() | ||
.collect(); | ||
|
||
(entries, settings) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
use clap::{arg, command, ArgAction}; | ||
use inquire::{ | ||
ui::{Color, IndexPrefix, RenderConfig, Styled}, | ||
InquireError, Select, | ||
|
@@ -206,45 +205,6 @@ pub async fn process_file( | |
(filename_without_ext, Some(new_name_base), true) | ||
} | ||
|
||
// Function to process the passed arguments | ||
pub fn process_args() -> (Vec<String>, HashMap<String, bool>) { | ||
let matches = command!() | ||
.name("movie-rename") | ||
.author("Sayantan Santra <[email protected]>") | ||
.about("A simple tool to rename movies, written in Rust.") | ||
.arg(arg!(-d --directory "Run in directory mode").action(ArgAction::SetTrue)) | ||
.arg(arg!(-n --"dry-run" "Do a dry run").action(ArgAction::SetTrue)) | ||
.arg(arg!(-l --"i-feel-lucky" "Always choose the first option").action(ArgAction::SetTrue)) | ||
.arg( | ||
arg!([entries] "The files/directories to be processed") | ||
.trailing_var_arg(true) | ||
.num_args(1..) | ||
.required(true), | ||
) | ||
// Use -v instead of -V for version | ||
.disable_version_flag(true) | ||
.arg(arg!(-v --version "Print version").action(ArgAction::Version)) | ||
.arg_required_else_help(true) | ||
.get_matches(); | ||
|
||
// Generate the settings HashMap from read flags | ||
let mut settings = HashMap::new(); | ||
for id in matches.ids().map(|x| x.as_str()) { | ||
if id != "entries" { | ||
settings.insert(id.to_string(), matches.get_flag(id)); | ||
} | ||
} | ||
|
||
// Every unmatched argument should be treated as a file entry | ||
let entries: Vec<String> = matches | ||
.get_many::<String>("entries") | ||
.expect("No entries provided!") | ||
.cloned() | ||
.collect(); | ||
|
||
(entries, settings) | ||
} | ||
|
||
// RenderConfig for the menu items | ||
fn get_render_config() -> RenderConfig { | ||
let mut render_config = RenderConfig::default(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters