2024-08-28 14:35:08 -05:00
|
|
|
use std::{fmt::format, io::Write};
|
|
|
|
|
|
|
|
pub enum Options {
|
|
|
|
Build,
|
|
|
|
Clean,
|
|
|
|
New,
|
|
|
|
Run,
|
|
|
|
}
|
|
|
|
|
|
|
|
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" => {
|
|
|
|
let name = &args[1];
|
|
|
|
build(name.to_string())
|
|
|
|
}
|
|
|
|
"new" => {
|
|
|
|
let binding = args.pop().unwrap();
|
|
|
|
let dev_type = binding.as_str();
|
|
|
|
let name = args.pop().unwrap();
|
|
|
|
match dev_type {
|
|
|
|
"lib" | "library" => new(true, name),
|
|
|
|
"prog" | "program" => new(false, name),
|
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
"run" => run(),
|
|
|
|
|
|
|
|
"help" => {
|
|
|
|
// println!("This is the help message.");
|
|
|
|
// println!("A prototype build tool meant to help with ableOS software development.");
|
|
|
|
help()
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
println!("Error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new(library: bool, name: String) {
|
|
|
|
let (folder_hierarchy, entry_name) = match library {
|
|
|
|
true => ("libraries", "lib.hb"),
|
|
|
|
false => ("programs", "main.hb"),
|
|
|
|
};
|
|
|
|
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();
|
|
|
|
let file_contents = if library {
|
|
|
|
""
|
|
|
|
} else {
|
|
|
|
"main := fn(): int {
|
|
|
|
return 0
|
|
|
|
}"
|
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
file.write_all(file_contents.as_bytes()).unwrap();
|
|
|
|
|
2024-08-29 06:51:48 -05:00
|
|
|
println!("New project created.");
|
|
|
|
if !library {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn help() {
|
|
|
|
println!(
|
|
|
|
"==========
|
|
|
|
= Help =
|
|
|
|
==========
|
|
|
|
Subcommands
|
|
|
|
- new Usage: `cargo dev new library name` or `cargo dev new program name`"
|
|
|
|
)
|
|
|
|
}
|