Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use std::path::PathBuf;
#[derive(Clap, Debug)]
#[clap(author, version)]
pub struct App {
/// Uses default commit types, Cargo.toml requires no changes.
#[clap(long, short = 'd')]
pub default: bool,
/// Opens the user's editor after the questioning process.
#[clap(long, short = 'e')]
pub edit: bool,
Expand Down
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod cargo;
mod git;
mod questions;

fn run_dialog() -> Option<SurveyResults> {
fn run_dialog(app: &App) -> Option<SurveyResults> {
let manifest = parse_manifest().unwrap();
if let Some(package) = manifest.package {
if let Some(metadata) = package.metadata {
Expand All @@ -33,8 +33,11 @@ fn run_dialog() -> Option<SurveyResults> {
}

return Some(ask(types));
} else if app.default {
// Use default scopes only.
return Some(ask(DEFAULT_TYPES.clone()));
} else {
eprintln!("Please specify allowed scopes inside of your Cargo.toml file under the `package.metadata.cz` key!");
eprintln!("Please specify allowed scopes inside of your Cargo.toml file under the `package.metadata.commits` key!");
}
}

Expand All @@ -49,7 +52,7 @@ fn create_commit(commit_msg: &str, repo: &Path) {
fn run(app: App) {
// No point to continue if repo doesn't exist or there are no staged files
if check_staged_files_exist(app.repo_path.as_path()) {
let survey = run_dialog();
let survey = run_dialog(&app);
let commit_msg = survey.map(generate_commit_msg).and_then(|msg| {
if app.edit {
edit::edit(msg).ok()
Expand Down