git-gamble 2.14.1

blend TDD + TCR to make sure to develop the right thing 😌, baby step by baby step πŸ‘ΆπŸ¦Ά
Documentation
use std::path::PathBuf;

use clap::ArgAction;
use clap::ArgGroup;
use clap::Parser;
use clap::Subcommand;

#[cfg(feature = "with_subcommand_generate_shell_completions")]
use crate::git_gamble::subcommand_generate_shell_completions::cli::GenerateShellCompletions;

#[cfg(feature = "with_subcommand_hook")]
use crate::git_gamble::subcommand_hook::cli::SubCommandHook;

#[derive(Subcommand, Debug)]
pub enum OptionalSubcommands {
	#[cfg(feature = "with_subcommand_generate_shell_completions")]
	GenerateShellCompletions(GenerateShellCompletions),

	#[cfg(feature = "with_subcommand_hook")]
	#[command(subcommand)]
	Hook(SubCommandHook),
}

#[derive(Parser, Debug)]
#[command(
	version,
	infer_subcommands = true,
	subcommand_negates_reqs = true,
	group = ArgGroup::new("gambling").required(true),
	about(
		[
			"Blend TDD (Test Driven Development) + TCR (`test && commit || revert`) to make sure to develop",
			"the right thing 😌, baby step by baby step πŸ‘ΆπŸ¦Ά"
		].join("\n")
	),
	after_help(
		[
			"Any contributions (feedback, bug report, merge request ...) are welcome",
			"https://git-gamble.is-cool.dev/contributing/index.html"
		].join("\n")
	)
)]
pub struct Cli {
	// subcommands
	#[command(subcommand)]
	pub optional_subcommands: Option<OptionalSubcommands>,

	// flags
	/// Gamble that tests should pass
	#[arg(
		short = 'g',
		long,
		group = "gambling",
		visible_aliases = &["green", "refactor"],
		display_order = 1,
	)]
	pub pass: bool,
	/// Gamble that tests should fail
	#[arg(
		short = 'r',
		long,
		group = "gambling",
		visible_alias = "red",
		display_order = 1
	)]
	pub fail: bool,

	/// Do not make any changes
	/// and run test command
	#[arg(short = 'n', long)]
	pub dry_run: bool,

	/// Do not run git hooks
	#[arg(long)]
	pub no_verify: bool,

	// options
	/// Repository path
	// reflect `git -C <repository-path>`
	#[arg(short = 'C', long, default_value = ".")]
	pub repository_path: PathBuf,

	/// Commit's message
	#[arg(short = 'm', long, default_value = "")]
	pub message: String,

	/// Open editor to edit commit's message
	#[arg(short = 'e', long)]
	pub edit: bool,

	/// Fixes up commit
	#[arg(long, group = "rebase-message")]
	pub fixup: Option<String>,

	/// Construct a commit message for use with `rebase --autosquash`
	#[arg(long, group = "rebase-message")]
	pub squash: Option<String>,

	// rest arguments
	/// The command to execute to know the result
	#[arg(
		env = "GAMBLE_TEST_COMMAND",
		action(ArgAction::Append),
		last = true,
		required = true
	)]
	pub test_command: Vec<String>,
}

#[test]
fn verify_app() {
	use clap::CommandFactory;

	Cli::command().debug_assert()
}