more dev work
This commit is contained in:
51
src/app.rs
51
src/app.rs
@@ -4,6 +4,7 @@ use std::{
|
||||
process::Command,
|
||||
};
|
||||
|
||||
use colored::Colorize;
|
||||
use glob::glob;
|
||||
|
||||
const MAIN_C: &str = include_str!("templates/main.c");
|
||||
@@ -41,28 +42,26 @@ impl App {
|
||||
pub fn run(self) {
|
||||
match self.command {
|
||||
Subcommand::New { name } => match create_project(&name) {
|
||||
Ok(_) => println!("Successfully created new project '{name}'."),
|
||||
Err(e) => {
|
||||
eprintln!("Error creating project '{name}': {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Subcommand::Init => match create_project(".") {
|
||||
Ok(_) => println!("Successfully initialized new project."),
|
||||
Err(e) => {
|
||||
eprintln!("Error initializing project: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Subcommand::Run { mode, args } => {
|
||||
match build(&mode) {
|
||||
Ok(_) => {
|
||||
println!("Successfully built project.");
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error building project: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
if let Err(e) = run(&mode, args) {
|
||||
eprintln!("Error running project: {e}");
|
||||
@@ -70,19 +69,29 @@ impl App {
|
||||
}
|
||||
}
|
||||
Subcommand::Build { mode } => match build(&mode) {
|
||||
Ok(_) => {
|
||||
println!("Successfully built project.");
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error building project: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
if pathdir.exists() && pathdir.to_string_lossy() != "." {
|
||||
@@ -135,6 +144,15 @@ fn build(mode: &Option<String>) -> std::io::Result<()> {
|
||||
"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))?;
|
||||
|
||||
let mut command = Command::new("gcc");
|
||||
@@ -159,6 +177,16 @@ fn build(mode: &Option<String>) -> std::io::Result<()> {
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -176,6 +204,13 @@ fn run(mode: &Option<String>, args: Option<Vec<String>>) -> std::io::Result<()>
|
||||
"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));
|
||||
|
||||
if let Some(args) = args {
|
||||
|
||||
Reference in New Issue
Block a user