From c3f6733a70ea0b5d952a37d4873546b5b591a721 Mon Sep 17 00:00:00 2001 From: colomboalb Date: Thu, 7 Nov 2019 23:52:04 +0100 Subject: [PATCH] docs: improve help and error messages --- src/main.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 658ec02..b9625ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,23 +26,30 @@ mod changelog; #[derive(Debug, StructOpt)] #[structopt(name = "what-bump")] struct Config { - /// Analyse commits up to this one (exclusive) - #[structopt(required_unless = "bump", default_value = "")] - up_to_revision: String, + /// Analyse commits up to this one (exclusive). + /// + /// This would normally be the commit corresponding to your previous release (it can be + /// a tag, a commit id, or anything else that GIT can parse). + #[structopt(required_unless = "bump")] + up_to_revision: Option, - /// Current version of your software + /// Current version of your software. #[structopt(long, short)] from: Option, - /// Location of the GIT repo + /// Location of the GIT repo. #[structopt(long, short, default_value = "./")] path: repo::ConventionalRepo, - /// Also generate a changelog, and write it to this file + /// Also generate a changelog, and write it to this file. #[structopt(long, short)] changelog: Option, - /// Perform the specified version bump (you must also specify `--from`) + /// Perform the specified version bump (you must also specify `--from`). + /// + /// Use this option if you know both the previous version, and the type of bump you need + /// to do. This will skip the analysis of commit messages, therefore you don't need to + /// provide a commit id if you use this option. #[structopt(long, short)] bump: Option, } @@ -61,7 +68,8 @@ fn main() -> Result<(), Box> { _ => (), } - let max_bump_type = config.path.commits_up_to(&config.up_to_revision)? + let up_to_revision = config.up_to_revision.unwrap(); + let max_bump_type = config.path.commits_up_to(&up_to_revision)? .map(|commit| Ok(BumpType::from(commit.message().unwrap_or("")))) .max()? .unwrap_or_default(); @@ -74,7 +82,7 @@ fn main() -> Result<(), Box> { if let Some(cl_path) = config.changelog { use askama::Template; - let mut changelog = ChangeLog::new(config.path.commits_up_to(&config.up_to_revision)?)?; + let mut changelog = ChangeLog::new(config.path.commits_up_to(&up_to_revision)?)?; if let Some(new_version) = new_version { changelog.version = new_version; }