Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
ysawa0 committed Nov 10, 2023
1 parent d0dbc46 commit bedc2d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
mod python;

use std::process;

use clap::Parser;
use python::setup_preset;
use regex::Regex;

#[derive(Parser)]
#[clap(
Expand Down Expand Up @@ -34,19 +37,30 @@ struct UpdateArgs {
preset: String,
}

fn check_pyver(preset: &str) {
let re = Regex::new(r"python(3\.\d+|4\.\d+)").unwrap();
// if let Some(caps) = re.captures(preset) {
if re.captures(preset).is_none() {
eprintln!("Python version not recognized in --preset, invalid input. Expected format: 'python3.xx'");
process::exit(1);
};
}

fn main() {
match Cli::parse() {
Cli::Create(args) => {
println!("Creating project with name: {}", args.name);
println!("Using preset: {:?} ", args.preset);
if args.preset.starts_with("python") {
check_pyver(&args.preset);
setup_preset(&args.preset, args.name, true);
} else {
eprintln!("Preset: {:?} not supported", args.preset);
}
}
Cli::Update(args) => {
println!("Updating project with preset: {:?}", args.preset);
check_pyver(&args.preset);
setup_preset(&args.preset, "".to_string(), false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn setup_preset(mut preset: &str, name: String, create: bool) {
let ver = caps[1].to_string();
(ver.clone(), format!("py{}", ver.replace('.', "")))
} else {
eprintln!("Python version not recognized in --preset, invalid input");
eprintln!("Python version not recognized in --preset, invalid input. Expected format: 'python3.xx'");
process::exit(1);
};

Expand Down

0 comments on commit bedc2d6

Please sign in to comment.