Skip to content

Commit 09f1335

Browse files
committed
add get-pip.py executor command
1 parent e0b4d33 commit 09f1335

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

src/backend/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod env;
2+
pub mod python_tools;
23
pub mod utils;

src/backend/python_tools.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
pub fn get_pip(python_path: &String) {
2+
use colored::Colorize;
3+
4+
println!("{}", "Downloading get-pip.py...".cyan());
5+
let url = "https://bootstrap.pypa.io/get-pip.py";
6+
let response = reqwest::blocking::get(url)
7+
.expect("Failed to fetch get-pip.py")
8+
.text()
9+
.expect("Failed to read response text");
10+
11+
println!("{}", "Writing temporary file...".cyan());
12+
std::fs::write("get_pip_temp.py", response).unwrap();
13+
14+
println!(
15+
"{} {}",
16+
"Installing pip using:".cyan(),
17+
python_path.yellow()
18+
);
19+
let status = std::process::Command::new(python_path)
20+
.arg("get_pip_temp.py")
21+
.status()
22+
.expect("Failed to run get-pip.py");
23+
24+
std::fs::remove_file("get_pip_temp.py").expect("Failed to remove temporary file");
25+
26+
if status.success() {
27+
println!("{}", "✓ pip installed successfully!".green().bold());
28+
} else {
29+
println!("{}", "✗ Failed to install pip".red().bold());
30+
}
31+
}

src/main.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clap::{value_parser, Arg, ArgMatches, Command};
22

33
mod backend;
4+
mod editor;
45

56
fn main() {
67
let matches = clap::Command::new("externkit")
@@ -72,14 +73,46 @@ fn main() {
7273
),
7374
),
7475
)
75-
.subcommand(Command::new("init").about("Initialize the externkit project"));
76+
.subcommand(Command::new("init").about("Initialize the externkit project"))
77+
.subcommand(
78+
Command::new("get_pip")
79+
.about("Fetch and run get-pip.py script")
80+
.arg(
81+
Arg::new("python_path")
82+
.long("python-path")
83+
.help("The python executable to use")
84+
.value_parser(value_parser!(String)),
85+
),
86+
)
87+
.subcommand(
88+
Command::new("edit")
89+
.about("Open the nano-like text editor")
90+
.arg(
91+
Arg::new("file")
92+
.help("File to edit")
93+
.value_parser(value_parser!(String)),
94+
),
95+
);
7696

7797
let matches = matches.get_matches();
7898
let project_path = std::path::PathBuf::from("./.externkit");
7999
match matches.subcommand() {
80100
Some(("init", _)) => {
81101
backend::utils::init_project();
82102
}
103+
Some(("get_pip", sub_matches)) => {
104+
backend::python_tools::get_pip(
105+
sub_matches
106+
.get_one::<String>("python_path")
107+
.unwrap_or(&"python".to_string()),
108+
);
109+
}
110+
Some(("edit", sub_matches)) => {
111+
let filename = sub_matches.get_one::<String>("file");
112+
if let Err(e) = editor::start_editor(filename.map(|s| s.as_str())) {
113+
eprintln!("Editor error: {}", e);
114+
}
115+
}
83116
Some((cmd, _)) if cmd == "help" || cmd == "version" => {}
84117
_ => {
85118
if !project_path.exists() {

0 commit comments

Comments
 (0)