more dev work
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -98,6 +98,15 @@ version = "1.0.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colored"
|
||||||
|
version = "3.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@@ -149,6 +158,7 @@ name = "pallet"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
|
"colored",
|
||||||
"glob",
|
"glob",
|
||||||
"serde",
|
"serde",
|
||||||
"toml",
|
"toml",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.6.0", features = ["derive"] }
|
clap = { version = "4.6.0", features = ["derive"] }
|
||||||
|
colored = "3.1.1"
|
||||||
glob = "0.3.3"
|
glob = "0.3.3"
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
toml = "1.0.7"
|
toml = "1.0.7"
|
||||||
|
|||||||
51
src/app.rs
51
src/app.rs
@@ -4,6 +4,7 @@ use std::{
|
|||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use colored::Colorize;
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
|
|
||||||
const MAIN_C: &str = include_str!("templates/main.c");
|
const MAIN_C: &str = include_str!("templates/main.c");
|
||||||
@@ -41,28 +42,26 @@ impl App {
|
|||||||
pub fn run(self) {
|
pub fn run(self) {
|
||||||
match self.command {
|
match self.command {
|
||||||
Subcommand::New { name } => match create_project(&name) {
|
Subcommand::New { name } => match create_project(&name) {
|
||||||
Ok(_) => println!("Successfully created new project '{name}'."),
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Error creating project '{name}': {e}");
|
eprintln!("Error creating project '{name}': {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
},
|
},
|
||||||
Subcommand::Init => match create_project(".") {
|
Subcommand::Init => match create_project(".") {
|
||||||
Ok(_) => println!("Successfully initialized new project."),
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Error initializing project: {e}");
|
eprintln!("Error initializing project: {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
},
|
},
|
||||||
Subcommand::Run { mode, args } => {
|
Subcommand::Run { mode, args } => {
|
||||||
match build(&mode) {
|
match build(&mode) {
|
||||||
Ok(_) => {
|
|
||||||
println!("Successfully built project.");
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Error building project: {e}");
|
eprintln!("Error building project: {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
};
|
};
|
||||||
if let Err(e) = run(&mode, args) {
|
if let Err(e) = run(&mode, args) {
|
||||||
eprintln!("Error running project: {e}");
|
eprintln!("Error running project: {e}");
|
||||||
@@ -70,19 +69,29 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Subcommand::Build { mode } => match build(&mode) {
|
Subcommand::Build { mode } => match build(&mode) {
|
||||||
Ok(_) => {
|
|
||||||
println!("Successfully built project.");
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Error building project: {e}");
|
eprintln!("Error building project: {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_project<P: AsRef<Path>>(directory: P) -> std::io::Result<()> {
|
fn create_project<P: AsRef<Path>>(directory: P) -> std::io::Result<()> {
|
||||||
|
let name = if directory.as_ref().to_string_lossy() == "." {
|
||||||
|
String::new()
|
||||||
|
} else {
|
||||||
|
format!(" '{}'", directory.as_ref().to_string_lossy())
|
||||||
|
};
|
||||||
|
|
||||||
|
println!(
|
||||||
|
" {} binary (application){}",
|
||||||
|
"Creating".green().bold(),
|
||||||
|
name
|
||||||
|
);
|
||||||
|
|
||||||
let pathdir = directory.as_ref();
|
let pathdir = directory.as_ref();
|
||||||
|
|
||||||
if pathdir.exists() && pathdir.to_string_lossy() != "." {
|
if pathdir.exists() && pathdir.to_string_lossy() != "." {
|
||||||
@@ -135,6 +144,15 @@ fn build(mode: &Option<String>) -> std::io::Result<()> {
|
|||||||
"build layout not found",
|
"build layout not found",
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
" {} '{}' profile for project '{}'",
|
||||||
|
"Building".green().bold(),
|
||||||
|
build_config.name,
|
||||||
|
conf.name
|
||||||
|
);
|
||||||
|
|
||||||
|
let start = std::time::Instant::now();
|
||||||
|
|
||||||
std::fs::create_dir_all(format!("target/{}", build_config.name))?;
|
std::fs::create_dir_all(format!("target/{}", build_config.name))?;
|
||||||
|
|
||||||
let mut command = Command::new("gcc");
|
let mut command = Command::new("gcc");
|
||||||
@@ -159,6 +177,16 @@ fn build(mode: &Option<String>) -> std::io::Result<()> {
|
|||||||
|
|
||||||
child.wait()?;
|
child.wait()?;
|
||||||
|
|
||||||
|
let stop = start.elapsed();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
" {} '{}' profile for project '{}' in {:.2}s",
|
||||||
|
"Finished".green().bold(),
|
||||||
|
build_config.name,
|
||||||
|
conf.name,
|
||||||
|
stop.as_secs_f64()
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,6 +204,13 @@ fn run(mode: &Option<String>, args: Option<Vec<String>>) -> std::io::Result<()>
|
|||||||
"build layout not found",
|
"build layout not found",
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
" {} '{}' profile for project '{}'",
|
||||||
|
"Running".green().bold(),
|
||||||
|
build_config.name,
|
||||||
|
conf.name
|
||||||
|
);
|
||||||
|
|
||||||
let mut command = Command::new(format!("target/{}/{}", build_config.name, conf.name));
|
let mut command = Command::new(format!("target/{}/{}", build_config.name, conf.name));
|
||||||
|
|
||||||
if let Some(args) = args {
|
if let Some(args) = args {
|
||||||
|
|||||||
Reference in New Issue
Block a user