Init: init first version of pcode-cli

Change log:
* Added the ability to display a list of all templates.
* Added the ability to download a template.
* Defined the project structure.
This commit is contained in:
Kirill Samoylenkov 2025-11-22 20:32:11 +05:00
parent 06e8ed4db0
commit 671c86870c
17 changed files with 848 additions and 0 deletions

67
src/lib.rs Normal file
View file

@ -0,0 +1,67 @@
mod cli;
mod config;
mod core;
mod misc;
mod templates;
use std::process;
use clap::Parser;
use cli::{CLI, Commands, TemplateAction};
use config::{Config, load_config};
use templates::{list_templates, load_template};
fn parse_config() -> Config {
let cfg: Config = match load_config() {
Ok(cfg) => cfg,
Err(err) => {
eprintln!("{}", err);
process::exit(1);
}
};
cfg
}
fn process_command(cfg: Config) {
let cli = CLI::parse();
match cli.command {
Some(Commands::Template(template_command)) => match template_command.action {
TemplateAction::List => {
let templates = match list_templates(&cfg.templates_dir) {
Ok(temps) => temps,
Err(err) => {
eprintln!("{}", err);
process::exit(1);
}
};
// TODO: Add grouping by language.
for template in templates {
eprintln!("{} >- {}", template.language, template.name);
}
}
TemplateAction::Load { name, vars } => match load_template(&cfg.templates_dir, &name) {
Ok(_) => {
eprintln!("Template succesfully copied!");
eprintln!("Vars: {:?}", vars);
}
Err(err) => {
eprintln!("{}", err);
process::exit(1)
}
},
},
None => {
eprintln!("No command provided. Use --help for usage.");
process::exit(1);
}
}
}
pub fn run() {
let cfg = parse_config();
process_command(cfg);
}