diff --git a/Cargo.lock b/Cargo.lock index 2c6cfd2..5e04e55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,7 +155,7 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "pallet" -version = "0.1.0" +version = "1.0.0" dependencies = [ "clap", "colored", diff --git a/Cargo.toml b/Cargo.toml index c6f8d05..7fbee31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet" -version = "0.1.0" +version = "1.0.0" edition = "2024" [dependencies] diff --git a/src/app.rs b/src/app.rs index de44063..0fefe24 100644 --- a/src/app.rs +++ b/src/app.rs @@ -8,8 +8,10 @@ use colored::Colorize; use glob::glob; const MAIN_C: &str = include_str!("templates/main.c"); +const GITIGNORE: &str = include_str!("templates/gitignoretemplate"); #[derive(clap::Parser)] +#[clap(version)] pub struct App { #[clap(subcommand)] command: Subcommand, @@ -36,6 +38,8 @@ enum Subcommand { /// The build mode to use mode: Option, }, + /// Clean all in progress files + Clean, } impl App { @@ -75,6 +79,13 @@ impl App { } _ => {} }, + Subcommand::Clean => match clean() { + Err(e) => { + eprintln!("Error cleaning project: {e}"); + std::process::exit(1); + } + _ => {} + }, } } } @@ -110,6 +121,7 @@ fn create_project>(directory: P) -> std::io::Result<()> { std::fs::create_dir("src")?; std::fs::write("src/main.c", MAIN_C)?; + std::fs::write(".gitignore", GITIGNORE)?; let config = crate::config::Config::new(&pathdir.to_string_lossy()); @@ -225,3 +237,21 @@ fn run(mode: &Option, args: Option>) -> std::io::Result<()> Ok(()) } + +fn clean() -> std::io::Result<()> { + if let None = get_config() { + return Err(std::io::Error::new( + std::io::ErrorKind::NotFound, + "no Pallet.toml found in local dir", + )); + } + + std::fs::remove_dir_all("target/")?; + + println!( + " {} removed files in target/ directory", + "Successfully".green().bold() + ); + + Ok(()) +} diff --git a/src/templates/gitignoretemplate b/src/templates/gitignoretemplate new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/src/templates/gitignoretemplate @@ -0,0 +1 @@ +target/