refactor: use defaults via clap
This commit is contained in:
parent
fae0a52a01
commit
fae049fbb0
23
src/main.rs
23
src/main.rs
|
@ -38,9 +38,9 @@ use sha1::{Digest, Sha1};
|
|||
/// since using a key ID goes through gpg-agent, which is very slow.
|
||||
#[derive(Parser)]
|
||||
struct Cli {
|
||||
/// The commit to replace with a vanity hash. Defaults to HEAD.
|
||||
#[arg(short, long)]
|
||||
commit: Option<String>,
|
||||
/// The commit to replace with a vanity hash.
|
||||
#[arg(short, long, default_value_t = String::from("HEAD"))]
|
||||
commit: String,
|
||||
|
||||
/// The key ID to use for signing.
|
||||
///
|
||||
|
@ -56,13 +56,11 @@ struct Cli {
|
|||
signing_key_file: Option<String>,
|
||||
|
||||
/// The number of threads to use when searching for a matching hash.
|
||||
/// Defaults to 0, and 0 will use the number of logical cores on your
|
||||
/// system.
|
||||
#[arg(short, long)]
|
||||
threads: Option<usize>,
|
||||
/// 0 will use the number of logical cores on your system.
|
||||
#[arg(short, long, default_value_t = 0)]
|
||||
threads: usize,
|
||||
|
||||
/// The method of changing the commit to generate a new hash. Defaults to
|
||||
/// decrement.
|
||||
/// The method of changing the commit to generate a new hash.
|
||||
///
|
||||
/// Note that this has no effect if a signing key is provided.
|
||||
///
|
||||
|
@ -75,7 +73,7 @@ struct Cli {
|
|||
///
|
||||
/// - counter will append an increasing number to the commit message for
|
||||
/// each attempt
|
||||
#[arg(short, long, value_enum, default_value_t = Method::Decrement)]
|
||||
#[arg(short, long, value_enum, default_value_t = Method::Counter)]
|
||||
method: Method,
|
||||
|
||||
/// Force generating a new vanity hash for commits that already start with
|
||||
|
@ -103,8 +101,7 @@ fn main() -> Result<()> {
|
|||
}
|
||||
|
||||
let prefix = args.prefix.to_lowercase();
|
||||
let commit = args.commit.as_deref().unwrap_or("HEAD");
|
||||
let threads = match args.threads.unwrap_or(0) {
|
||||
let threads = match args.threads {
|
||||
0 => num_cpus::get(),
|
||||
x => x,
|
||||
};
|
||||
|
@ -160,7 +157,7 @@ fn main() -> Result<()> {
|
|||
let repo = Repository::open(".")
|
||||
.context("no git repository in this directory")?;
|
||||
|
||||
let obj = repo.revparse_single(commit)
|
||||
let obj = repo.revparse_single(&args.commit)
|
||||
.context("could not find reference")?;
|
||||
let commit = repo.find_commit(obj.id())
|
||||
.context("could not resolve reference to a commit")?;
|
||||
|
|
Loading…
Reference in New Issue