Skip to content

Commit bedc2d6

Browse files
committed
clean
1 parent d0dbc46 commit bedc2d6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
mod python;
22

3+
use std::process;
4+
35
use clap::Parser;
46
use python::setup_preset;
7+
use regex::Regex;
58

69
#[derive(Parser)]
710
#[clap(
@@ -34,19 +37,30 @@ struct UpdateArgs {
3437
preset: String,
3538
}
3639

40+
fn check_pyver(preset: &str) {
41+
let re = Regex::new(r"python(3\.\d+|4\.\d+)").unwrap();
42+
// if let Some(caps) = re.captures(preset) {
43+
if re.captures(preset).is_none() {
44+
eprintln!("Python version not recognized in --preset, invalid input. Expected format: 'python3.xx'");
45+
process::exit(1);
46+
};
47+
}
48+
3749
fn main() {
3850
match Cli::parse() {
3951
Cli::Create(args) => {
4052
println!("Creating project with name: {}", args.name);
4153
println!("Using preset: {:?} ", args.preset);
4254
if args.preset.starts_with("python") {
55+
check_pyver(&args.preset);
4356
setup_preset(&args.preset, args.name, true);
4457
} else {
4558
eprintln!("Preset: {:?} not supported", args.preset);
4659
}
4760
}
4861
Cli::Update(args) => {
4962
println!("Updating project with preset: {:?}", args.preset);
63+
check_pyver(&args.preset);
5064
setup_preset(&args.preset, "".to_string(), false);
5165
}
5266
}

src/python.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn setup_preset(mut preset: &str, name: String, create: bool) {
107107
let ver = caps[1].to_string();
108108
(ver.clone(), format!("py{}", ver.replace('.', "")))
109109
} else {
110-
eprintln!("Python version not recognized in --preset, invalid input");
110+
eprintln!("Python version not recognized in --preset, invalid input. Expected format: 'python3.xx'");
111111
process::exit(1);
112112
};
113113

0 commit comments

Comments
 (0)