diff --git a/Cargo.toml b/Cargo.toml index 3c9e1d9..0bb2bb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,8 +23,6 @@ notify-debouncer-mini = "0.2" ron = "0.8" serde = { version = "1.0", features = ["derive"] } termion = "1.5" -# tree-sitter = "0.20" -# tree-sitter-c = "0.20" [profile.release] lto = true diff --git a/src/config.rs b/src/config.rs index 7ac1deb..9d2da36 100644 --- a/src/config.rs +++ b/src/config.rs @@ -36,7 +36,12 @@ impl Config { fs::write(path, content).unwrap(); } - pub fn get_current() -> Self { + pub fn get_local() -> Option { + let path = env::current_dir().unwrap(); + Self::get(&path) + } + + pub fn get_local_or_default() -> Self { let path = env::current_dir().unwrap(); Self::get(&path) .unwrap_or_else(|| Self::new(path.file_name().unwrap().to_str().unwrap().to_string())) diff --git a/src/main.rs b/src/main.rs index b68e073..138d37e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use config::Config; pub mod check; pub mod config; +pub mod push; pub mod run; pub mod tasks; pub mod test; @@ -68,12 +69,12 @@ pub enum Commands { }, /// Pushes changes to the git server with a custom tag. - push, + push { message: Option }, } fn append_includes(list: &mut Vec) { list.extend( - Config::get_current() + Config::get_local_or_default() .includes() .iter() .map(|f| f.to_string()), @@ -86,7 +87,7 @@ fn compilation_args() -> Vec { "-Wextra".to_string(), "-std=c99".to_string(), ]; - if Config::get_current().strict_mode() { + if Config::get_local_or_default().strict_mode() { args.push("-Werror".to_string()); } args @@ -102,7 +103,7 @@ fn main() { Commands::run { mut files } => { if files.is_empty() { - files.push(Config::get_current().main_file().to_string()); + files.push(Config::get_local_or_default().main_file().to_string()); } append_includes(&mut files); let args = compilation_args(); @@ -115,7 +116,7 @@ fn main() { tests, } => { if files.is_empty() { - files.push(Config::get_current().test_file().to_string()); + files.push(Config::get_local_or_default().test_file().to_string()); } append_includes(&mut files); let args = compilation_args(); @@ -132,8 +133,8 @@ fn main() { config::create(path, identifier); } - Commands::push => { - todo!(); + Commands::push { message } => { + push::main(message); } } } diff --git a/src/push.rs b/src/push.rs new file mode 100644 index 0000000..c2e355b --- /dev/null +++ b/src/push.rs @@ -0,0 +1,35 @@ +use std::process::Command; + +use chrono::Utc; + +use crate::{config::Config, utils::log_success}; + +pub fn main(message: Option) { + let message = message.unwrap_or_else(|| Utc::now().format("pi - %d/%m/%Y %H:%M").to_string()); + + // commit + Command::new("git") + .args(["commit", "-m", &message]) + .status() + .unwrap(); + + // push + Command::new("git").arg("push").status().unwrap(); + + // tag + let timestamp = Utc::now().timestamp(); + let suffix = format!("pi-{timestamp}"); + let tag = Config::get_local().unwrap().identifier().to_string() + &suffix; + Command::new("git") + .args(["tag", "-a", &tag, "-m", ""]) + .status() + .unwrap(); + + // push tag + Command::new("git") + .args(["push", "--follow-tags"]) + .status() + .unwrap(); + + log_success(&format!("pushed with tag '{tag}'")); +}