2024-08-30 07:38:04 -05:00
|
|
|
use std::io::Write;
|
2024-08-30 12:31:45 -05:00
|
|
|
|
|
|
|
use idl::build_idl;
|
2024-08-30 07:38:04 -05:00
|
|
|
pub mod idl;
|
2024-08-28 14:35:08 -05:00
|
|
|
|
|
|
|
pub enum Options {
|
|
|
|
Build,
|
|
|
|
Clean,
|
|
|
|
New,
|
|
|
|
Run,
|
|
|
|
}
|
2024-08-30 12:31:45 -05:00
|
|
|
#[derive(PartialEq, Debug)]
|
2024-08-30 07:38:04 -05:00
|
|
|
pub enum DevelopmentType {
|
|
|
|
Program,
|
|
|
|
Library,
|
|
|
|
IDL,
|
|
|
|
}
|
2024-08-28 14:35:08 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut args: Vec<String> = std::env::args().collect();
|
|
|
|
args.remove(0);
|
|
|
|
args.reverse();
|
|
|
|
|
|
|
|
let binding = args.pop().unwrap_or("help".to_string());
|
|
|
|
let subcommand = binding.as_str();
|
|
|
|
|
|
|
|
match subcommand {
|
|
|
|
"build" => {
|
2024-08-30 12:31:45 -05:00
|
|
|
let name = &args.pop().unwrap();
|
2024-08-28 14:35:08 -05:00
|
|
|
build(name.to_string())
|
|
|
|
}
|
|
|
|
"new" => {
|
|
|
|
let binding = args.pop().unwrap();
|
|
|
|
let dev_type = binding.as_str();
|
|
|
|
let name = args.pop().unwrap();
|
2024-08-30 07:38:04 -05:00
|
|
|
use DevelopmentType::*;
|
2024-08-28 14:35:08 -05:00
|
|
|
match dev_type {
|
2024-08-30 07:38:04 -05:00
|
|
|
"lib" | "library" => new(Library, name),
|
|
|
|
"prog" | "program" => new(Program, name),
|
|
|
|
"idl" => {
|
|
|
|
new(IDL, name);
|
|
|
|
// idl::main();
|
|
|
|
panic!("IDL is not finalized yet.")
|
|
|
|
}
|
2024-08-28 14:35:08 -05:00
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
"run" => run(),
|
2024-08-30 07:38:04 -05:00
|
|
|
"help" => help(),
|
2024-08-28 14:35:08 -05:00
|
|
|
_ => {
|
|
|
|
println!("Error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-30 07:38:04 -05:00
|
|
|
pub fn new(development_type: DevelopmentType, name: String) {
|
|
|
|
let (folder_hierarchy, entry_name) = match development_type {
|
|
|
|
DevelopmentType::Program => ("programs", "main.hb"),
|
|
|
|
DevelopmentType::Library => ("libraries", "lib.hb"),
|
|
|
|
DevelopmentType::IDL => ("idl", "protocol.aidl"),
|
2024-08-28 14:35:08 -05:00
|
|
|
};
|
|
|
|
let project_folder_path_string = format!("sysdata/{folder_hierarchy}/{name}");
|
|
|
|
|
|
|
|
if std::path::Path::new(&project_folder_path_string).exists() {
|
|
|
|
panic!("Project already exists.")
|
|
|
|
}
|
|
|
|
|
|
|
|
std::fs::create_dir(project_folder_path_string.clone()).unwrap();
|
|
|
|
let readme_path_string = format!("{}/README.md", project_folder_path_string);
|
|
|
|
let mut readme_file = std::fs::File::create(readme_path_string.clone()).unwrap();
|
|
|
|
|
|
|
|
let readme_contents = format!("# {}", name);
|
|
|
|
readme_file.write_all(readme_contents.as_bytes()).unwrap();
|
|
|
|
|
|
|
|
let src_folder_path_string = format!("{}/src", project_folder_path_string);
|
|
|
|
std::fs::create_dir(src_folder_path_string.clone()).unwrap();
|
|
|
|
|
|
|
|
let full_path_string = format!("{src_folder_path_string}/{entry_name}");
|
|
|
|
let mut file = std::fs::File::create(full_path_string.clone()).unwrap();
|
2024-08-30 07:38:04 -05:00
|
|
|
let file_contents = match development_type {
|
|
|
|
DevelopmentType::Program => "main := fn(): int {
|
2024-08-28 14:35:08 -05:00
|
|
|
return 0
|
|
|
|
}"
|
2024-08-30 07:38:04 -05:00
|
|
|
.to_string(),
|
|
|
|
DevelopmentType::Library => "".to_string(),
|
|
|
|
DevelopmentType::IDL => format!(
|
|
|
|
"protocol {} {{
|
|
|
|
}}",
|
|
|
|
name
|
|
|
|
)
|
|
|
|
.to_owned(),
|
2024-08-28 14:35:08 -05:00
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
file.write_all(file_contents.as_bytes()).unwrap();
|
|
|
|
|
2024-08-29 06:51:48 -05:00
|
|
|
println!("New project created.");
|
2024-08-30 07:38:04 -05:00
|
|
|
if development_type == DevelopmentType::Program {
|
2024-08-29 06:51:48 -05:00
|
|
|
println!("You should add your project into the ableOS system configuration in sysdata/system_config.toml")
|
|
|
|
}
|
2024-08-28 14:35:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn run() {
|
|
|
|
println!("Running is not supported on a non-ableOS platform");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn build(name: String) {
|
|
|
|
println!("building {}", name);
|
2024-08-30 12:31:45 -05:00
|
|
|
let mut a = name.split("/");
|
|
|
|
let dev_type = a.next().unwrap();
|
|
|
|
let name = a.next().unwrap().to_string();
|
|
|
|
match dev_type {
|
|
|
|
"programs" => build_program(name),
|
|
|
|
"idl" => build_idl(name),
|
|
|
|
_ => {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
}
|
2024-08-28 14:35:08 -05:00
|
|
|
}
|
|
|
|
|
2024-08-30 12:31:45 -05:00
|
|
|
pub fn build_program(name: String) {}
|
|
|
|
pub fn build_library(name: String) {}
|
|
|
|
|
2024-08-28 14:35:08 -05:00
|
|
|
fn help() {
|
|
|
|
println!(
|
|
|
|
"==========
|
|
|
|
= Help =
|
|
|
|
==========
|
|
|
|
Subcommands
|
|
|
|
- new Usage: `cargo dev new library name` or `cargo dev new program name`"
|
|
|
|
)
|
|
|
|
}
|