diff --git a/Cargo.lock b/Cargo.lock index 652dcc1..a034220 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,7 +119,7 @@ checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" [[package]] name = "loki-cli" -version = "0.7.4" +version = "0.8.0" dependencies = [ "clap", "test-case", diff --git a/Cargo.toml b/Cargo.toml index 281ba8c..3944b9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "loki-cli" -version = "0.7.4" +version = "0.8.0" authors = ["Kyle W. Rader"] description = "Loki: 🚀 A Git productivity tool" homepage = "https://github.com/kyle-rader/loki-cli" diff --git a/src/main.rs b/src/main.rs index 6f67b8f..36c5351 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,14 @@ fn styles() -> clap::builder::Styles { const NO_HOOKS: &str = "core.hooksPath=/dev/null"; +#[derive(Debug, Parser)] +struct CommitOptions { + #[clap(short, long)] + all: bool, + /// Optional message to include. Each MESSAGE will be joined on whitespace. + message: Vec, +} + #[derive(Parser)] #[clap(version, about, author, color = clap::ColorChoice::Auto, styles = styles())] enum Cli { @@ -43,16 +51,17 @@ enum Cli { /// Pull with --prune deleting local branches pruned from the remote. Pull, + /// Fetch with --prune deleting local branches pruned from the remote. Fetch, + /// Add, commit, and push using a timestamp based commit message. - Save { - /// Include all untracked (new) files. - #[clap(short, long)] - all: bool, - /// Optional message to include. Each MESSAGE will be joined on whitespace and appended after timestamp. - message: Vec, - }, + #[clap(visible_alias = "s")] + Save(CommitOptions), + + /// Commit local changes + #[clap(visible_alias = "c")] + Commit(CommitOptions), /// Rebase the current branch onto the target branch after fetching. Rebase { @@ -79,7 +88,8 @@ fn main() -> Result<(), String> { Cli::Push { force } => push_branch(*force), Cli::Pull => pull_prune(), Cli::Fetch => fetch_prune(), - Cli::Save { all, message } => save(*all, message), + Cli::Save(CommitOptions { all, message }) => save(*all, message), + Cli::Commit(CommitOptions { all, message }) => commit(*all, message), Cli::Rebase { target } => rebase(target), Cli::NoHooks { command } => no_hooks(command), } @@ -121,10 +131,16 @@ fn rebase(target: &str) -> Result<(), String> { } fn save(all: bool, message: &[String]) -> Result<(), String> { + commit(all, message)?; + push_branch(false)?; + Ok(()) +} + +fn commit(all: bool, message: &[String]) -> Result<(), String> { let selector_option = if all { "--all" } else { "--update" }; let message = if message.is_empty() { - String::from("lk save") + String::from("lk commit") } else { // leading space important for the format of the message below. message.join(" ") @@ -133,7 +149,6 @@ fn save(all: bool, message: &[String]) -> Result<(), String> { git_commands_status(vec![ ("add files", vec!["add", selector_option]), ("commit", vec!["commit", "--message", message.as_str()]), - ("push", vec!["push"]), ])?; Ok(())