|
1 | 1 | use clap::{value_parser, Arg, ArgMatches, Command}; |
2 | 2 |
|
3 | 3 | mod backend; |
| 4 | +mod editor; |
4 | 5 |
|
5 | 6 | fn main() { |
6 | 7 | let matches = clap::Command::new("externkit") |
@@ -72,14 +73,46 @@ fn main() { |
72 | 73 | ), |
73 | 74 | ), |
74 | 75 | ) |
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 | + ); |
76 | 96 |
|
77 | 97 | let matches = matches.get_matches(); |
78 | 98 | let project_path = std::path::PathBuf::from("./.externkit"); |
79 | 99 | match matches.subcommand() { |
80 | 100 | Some(("init", _)) => { |
81 | 101 | backend::utils::init_project(); |
82 | 102 | } |
| 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 | + } |
83 | 116 | Some((cmd, _)) if cmd == "help" || cmd == "version" => {} |
84 | 117 | _ => { |
85 | 118 | if !project_path.exists() { |
|
0 commit comments