Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "loki-cli"
version = "0.9.2"
version = "0.9.3"
authors = ["Kyle W. Rader"]
description = "Loki: 🚀 A Git productivity tool"
homepage = "https://github.com/kyle-rader/loki-cli"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Loki: 🚀 A Git productivity tool
Usage: lk <COMMAND>

Commands:
new Create a new branch from HEAD and push it to origin. Set a prefix for all new branch names with the env var LOKI_NEW_PREFIX [aliases: n]
new Create a new branch from HEAD and push it to origin. Set a prefix with --prefix or the LOKI_NEW_PREFIX env var [aliases: n]
push Push the current branch to origin with --set-upstream [aliases: p]
pull Pull with --prune deleting local branches pruned from the remote
fetch Fetch with --prune deleting local branches pruned from the remote
Expand All @@ -43,7 +43,7 @@ Options:
Alias: `n`
* Make creating a new branch easier to type by joining all given args with a dash (`-`).
* Automatically push and setup tracking to `origin`.
* Set a prefix to always prepend with the `LOKI_NEW_PREFIX` environment variable.
* Set a prefix to always prepend with the `--prefix` flag or the `LOKI_NEW_PREFIX` environment variable.

#### Example
```
Expand Down
14 changes: 9 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ enum RepoSubcommand {
#[clap(version, about, author, color = clap::ColorChoice::Auto, styles = styles())]
enum Cli {
/// Create a new branch from HEAD and push it to origin.
/// Set a prefix for all new branch names with the env var LOKI_NEW_PREFIX
/// Set a prefix for all new branch names with `--prefix` or `LOKI_NEW_PREFIX`.
#[clap(visible_alias = "n")]
New {
/// Optional prefix to prepend to the generated branch name.
#[clap(long, env = "LOKI_NEW_PREFIX")]
prefix: Option<String>,

/// List of names to join with dashes to form a valid branch name.
name: Vec<String>,
},
Expand Down Expand Up @@ -109,7 +113,7 @@ fn main() -> Result<(), String> {
let cli = Cli::parse();

match &cli {
Cli::New { name } => new_branch(name),
Cli::New { name, prefix } => new_branch(name, prefix.as_deref()),
Cli::Push { force } => push_branch(*force),
Cli::Pull => pull_prune(),
Cli::Fetch => fetch_prune(),
Expand Down Expand Up @@ -313,15 +317,15 @@ fn commit(
Ok(())
}

fn new_branch(name: &[String]) -> Result<(), String> {
fn new_branch(name: &[String], prefix: Option<&str>) -> Result<(), String> {
if name.is_empty() {
return Err(String::from("name cannot be empty."));
}

let mut name = name.join("-");

if let Ok(prefix) = std::env::var(LOKI_NEW_PREFIX) {
eprintln!("Using prefix from env var {LOKI_NEW_PREFIX}={prefix}");
if let Some(prefix) = prefix {
eprintln!("Using branch prefix `{prefix}` (set via --prefix or {LOKI_NEW_PREFIX}).");
name = format!("{prefix}{name}");
}

Expand Down
Loading