fetch subcommand complete
This commit is contained in:
parent
019138f84d
commit
79e714d2d8
19
src/fetch.rs
19
src/fetch.rs
|
@ -15,6 +15,7 @@ pub fn fetch(extract_destination: &std::path::Path, verbose: bool) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Error fetching colorscripts archive: {}", e);
|
eprintln!("Error fetching colorscripts archive: {}", e);
|
||||||
|
cleanup().unwrap();
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -23,19 +24,31 @@ pub fn fetch(extract_destination: &std::path::Path, verbose: bool) {
|
||||||
// now we have the raw images
|
// now we have the raw images
|
||||||
match extract_colorscripts_archive() {
|
match extract_colorscripts_archive() {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => eprintln!("Error extracting colorscripts archive: {}", e),
|
Err(e) => {
|
||||||
|
eprintln!("Error extracting colorscripts archive: {}", e);
|
||||||
|
cleanup().unwrap();
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// crop images to content
|
// crop images to content
|
||||||
match crop_all_images_in_directory() {
|
match crop_all_images_in_directory() {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => eprintln!("Error cropping images: {}", e),
|
Err(e) => {
|
||||||
|
eprintln!("Error cropping images: {}", e);
|
||||||
|
cleanup().unwrap();
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// convert images to unicode, both small and big
|
// convert images to unicode, both small and big
|
||||||
match convert_images_to_ascii(extract_destination, verbose) {
|
match convert_images_to_ascii(extract_destination, verbose) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => eprintln!("Error converting images to ASCII: {}", e),
|
Err(e) => {
|
||||||
|
eprintln!("Error converting images to ASCII: {}", e);
|
||||||
|
cleanup().unwrap();
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
|
|
190
src/main.rs
190
src/main.rs
|
@ -1,99 +1,119 @@
|
||||||
use clap::Parser;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
# Arguments
|
# Arguments
|
||||||
|
## `fetch` - Fetch the latest colorscripts from the repository
|
||||||
|
- `extract_destination` - eXtract the colorscripts archive to a custom location
|
||||||
|
- `verbose` - Print colorscripts when generating
|
||||||
|
|
||||||
## Fetch
|
## `print` - Print a Pokemon colorscript
|
||||||
- `fetch` - Fetch the latest colorscripts from the repository
|
- `name` - Select Pokemon by name
|
||||||
- `extract_destination` - eXtract the colorscripts archive to a specified location
|
- `big` - Print a bigger version of the colorscript
|
||||||
- `verbose` - Print more information
|
- `list` - Print a list of all Pokemon names
|
||||||
|
- `random` - Print a random Pokemon colorscript
|
||||||
## Print
|
- `no-title` - Do not print Pokemon name
|
||||||
- `name` - Select pokemon by name
|
- `shiny` - Print the shiny version of the colorscript
|
||||||
- `big` - Show a bigger version of the sprite
|
|
||||||
- `list` - Show a list of all pokemon names
|
|
||||||
- `no-title` - Do not display pokemon name
|
|
||||||
- `shiny` - Show the shiny version of the sprite
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// Pokemon Colorscripts written in Rust
|
/// Pokemon Colorscripts written in Rust
|
||||||
#[derive(Parser, Debug)]
|
|
||||||
#[command(version, about, long_about = None)]
|
|
||||||
struct Args {
|
|
||||||
// fetch
|
|
||||||
/// Fetch the latest colorscripts from the repository
|
|
||||||
#[arg(short, long, default_value_t = false)]
|
|
||||||
fetch: bool,
|
|
||||||
|
|
||||||
// extract destination
|
|
||||||
/// eXtract the colorscripts archive to a specified location
|
|
||||||
#[arg(short = 'x', long = "extract", default_value_t = String::from(""))]
|
|
||||||
extract_destination: String,
|
|
||||||
|
|
||||||
// verbose
|
|
||||||
/// Don't print colorscripts to the console when generating
|
|
||||||
#[arg(long = "verbose", default_value_t = false)]
|
|
||||||
verbose: bool,
|
|
||||||
/*
|
|
||||||
// big
|
|
||||||
/// Show a bigger version of the sprite
|
|
||||||
#[arg(short, long, default_value_t = false)]
|
|
||||||
big: bool,
|
|
||||||
|
|
||||||
// list
|
|
||||||
/// Show a list of all pokemon names
|
|
||||||
#[arg(short, long, default_value_t = false)]
|
|
||||||
list: bool,
|
|
||||||
|
|
||||||
// name
|
|
||||||
/// Select pokemon by name
|
|
||||||
#[arg(short = 'a', long, default_value_t = String::from(""))]
|
|
||||||
name: String,
|
|
||||||
|
|
||||||
// no-title
|
|
||||||
// NOTE: clap will convert the kebab-case to snake_case
|
|
||||||
// very smart!
|
|
||||||
// ...but very annoying for beginners
|
|
||||||
/// Do not display pokemon name
|
|
||||||
#[arg(long, default_value_t = false)]
|
|
||||||
no_title: bool,
|
|
||||||
|
|
||||||
// shiny
|
|
||||||
/// Show the shiny version of the sprite
|
|
||||||
#[arg(short, long, default_value_t = false)]
|
|
||||||
shiny: bool,
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = argument_validation();
|
let args = argument_parser();
|
||||||
|
|
||||||
if args.fetch == true {
|
if let Some(fetch_args) = args.subcommand_matches("fetch") {
|
||||||
// get data directory
|
// fetch
|
||||||
let data_directory = match dirs::data_dir() {
|
let extract_destination_raw: &String =
|
||||||
Some(dir) => dir.join("rustmon"),
|
fetch_args.get_one::<String>("extract_destination").unwrap();
|
||||||
None => {
|
let extract_destination: &std::path::Path = std::path::Path::new(extract_destination_raw);
|
||||||
println!("Data directory not found");
|
let verbose: bool = fetch_args.get_flag("verbose");
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// decicde whether to use the default data directory or the one specified by the user
|
// display selections
|
||||||
// if the user specifies a directory, use that
|
println!("Extract destination: {}", extract_destination.display());
|
||||||
let extract_destination = if args.extract_destination.is_empty() {
|
println!("Verbose: {}", verbose);
|
||||||
data_directory
|
|
||||||
} else {
|
|
||||||
std::path::PathBuf::from(&args.extract_destination)
|
|
||||||
};
|
|
||||||
|
|
||||||
rustmon::fetch::fetch(&extract_destination, args.verbose);
|
// invoke bigchungus fetch function
|
||||||
} else {
|
rustmon::fetch::fetch(extract_destination, verbose)
|
||||||
println!("print deez nuts");
|
} else if let Some(print_args) = args.subcommand_matches("print") {
|
||||||
|
// print
|
||||||
|
if let Some(name) = print_args.get_one::<String>("name") {
|
||||||
|
// print/name
|
||||||
|
println!("name: {}", name);
|
||||||
|
}
|
||||||
|
if print_args.get_flag("big") {
|
||||||
|
// print/big
|
||||||
|
println!("big");
|
||||||
|
}
|
||||||
|
println!("something else");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn argument_validation() -> Args {
|
fn argument_parser() -> clap::ArgMatches {
|
||||||
let args = Args::parse();
|
return clap::command!()
|
||||||
|
// info
|
||||||
return args;
|
.about("Pokemon Colorscripts written in Rust")
|
||||||
|
.author("Vomitblood")
|
||||||
|
// fetch subcommand
|
||||||
|
.subcommand(
|
||||||
|
clap::Command::new("fetch")
|
||||||
|
.about("Fetch the latest colorscripts from the repository")
|
||||||
|
// fetch/extract_destination
|
||||||
|
.arg(
|
||||||
|
clap::Arg::new("extract_destination")
|
||||||
|
.help("eXtract the colorscripts archive to a custom location")
|
||||||
|
.short('x')
|
||||||
|
.long("extract-destination")
|
||||||
|
.default_value(&*rustmon::constants::DATA_DIRECTORY.to_str().unwrap()),
|
||||||
|
)
|
||||||
|
// fetch/verbose
|
||||||
|
.arg(
|
||||||
|
clap::Arg::new("verbose")
|
||||||
|
.help("Select Pokemon by name")
|
||||||
|
.short('v')
|
||||||
|
.long("verbose")
|
||||||
|
.action(clap::ArgAction::SetTrue),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// print subcommand
|
||||||
|
.subcommand(
|
||||||
|
clap::Command::new("print")
|
||||||
|
.about("Print a Pokemon colorscript")
|
||||||
|
// print/big
|
||||||
|
.arg(
|
||||||
|
clap::arg!(-b --big "Print a bigger version of the colorscript")
|
||||||
|
.conflicts_with("list"),
|
||||||
|
)
|
||||||
|
// print/list
|
||||||
|
.arg(
|
||||||
|
clap::arg!(-l --list "Print a list of all Pokemon names")
|
||||||
|
.conflicts_with("name")
|
||||||
|
.conflicts_with("random"),
|
||||||
|
)
|
||||||
|
// print/name
|
||||||
|
.arg(
|
||||||
|
clap::Arg::new("name")
|
||||||
|
.help("Select Pokemon by name")
|
||||||
|
.short('n')
|
||||||
|
.long("name")
|
||||||
|
.conflicts_with("list")
|
||||||
|
.conflicts_with("random"),
|
||||||
|
)
|
||||||
|
// print/random
|
||||||
|
.arg(
|
||||||
|
clap::arg!(-r --random "Print a random Pokemon colorscript")
|
||||||
|
.conflicts_with("list")
|
||||||
|
.conflicts_with("name"),
|
||||||
|
)
|
||||||
|
// print/no-title
|
||||||
|
.arg(
|
||||||
|
clap::Arg::new("no-title")
|
||||||
|
.help("Do not print Pokemon name")
|
||||||
|
.long("no-title")
|
||||||
|
.action(clap::ArgAction::SetTrue)
|
||||||
|
.conflicts_with("list"),
|
||||||
|
)
|
||||||
|
// print/shiny
|
||||||
|
.arg(
|
||||||
|
clap::arg!(-s --shiny "Print the shiny version of the colorscript")
|
||||||
|
.conflicts_with("list"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// finalize
|
||||||
|
.get_matches();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue