dev tool prototype

This commit is contained in:
Able 2024-08-28 14:35:08 -05:00
parent 0444fe4dfa
commit 1c491e70e0
7 changed files with 119 additions and 1 deletions

View file

@ -1,2 +1,3 @@
[alias] [alias]
repbuild = "run --manifest-path ./repbuild/Cargo.toml -r --" repbuild = "run --manifest-path ./repbuild/Cargo.toml -r --"
dev = "run --manifest-path ./dev/Cargo.toml -r --"

4
Cargo.lock generated
View file

@ -245,6 +245,10 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "dev"
version = "0.1.0"
[[package]] [[package]]
name = "embedded-graphics" name = "embedded-graphics"
version = "0.7.1" version = "0.7.1"

View file

@ -1,3 +1,3 @@
[workspace] [workspace]
resolver = "2" resolver = "2"
members = ["kernel", "repbuild"] members = [ "dev","kernel", "repbuild"]

View file

@ -19,3 +19,6 @@ For running AbleOS, `repbuild` uses QEMU.
1. Ensure you have qemu installed 1. Ensure you have qemu installed
2. `git submodule update --init` 2. `git submodule update --init`
3. `cargo repbuild run` 3. `cargo repbuild run`
# Developing
There is a new work in progress developer tool for hblang.

6
dev/Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "dev"
version = "0.1.0"
edition = "2021"
[dependencies]

6
dev/README.md Normal file
View file

@ -0,0 +1,6 @@
# dev
`dev` is an ableOS specific tool meant to help the development of ableOS.
At the current stage changes are not welcome. If you have feature suggestions ping me on discord `@abletheabove`.
Run `cargo dev help` to see usage.

98
dev/src/main.rs Normal file
View file

@ -0,0 +1,98 @@
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();
println!("{}", full_path_string);
}
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`"
)
}