pub enum CommitCommand {
Plan,
Scopes,
History {
range: Option<String>,
},
Validate {
file: Option<String>,
paths: Vec<String>,
rev: Option<String>,
},
}Expand description
The subcommands of majordomus commit: plan, scopes, history and validate.
All four are read-only. validate is the one the commit-msg hook runs, and its shape
is the hook’s: the file git will take the message from, and the paths that are staged,
so that a fix carrying no test among its files is judged rather than guessed at.
use clap::Parser;
use majordomus_cli::cli::{Cli, Command, CommitCommand};
let cli = Cli::try_parse_from([
"majordomus", "commit", "validate", ".git/COMMIT_EDITMSG",
"--paths", "apps/majordomus-cli/src/commit/mod.rs,test/cases/274_commit_policy.sh",
])
.unwrap();
let args = match cli.command {
Command::Commit(args) => args,
other => panic!("expected `commit`, parsed {other:?}"),
};
// `--paths` is comma-delimited, so the hook can hand over one `git diff --cached` line
assert!(matches!(
args.command,
Some(CommitCommand::Validate { file: Some(ref f), ref paths, rev: None })
if f == ".git/COMMIT_EDITMSG" && paths.len() == 2
));
// a revision instead of a file judges a commit already made, and the two are exclusive
assert!(Cli::try_parse_from(["majordomus", "commit", "validate", "--rev", "HEAD"]).is_ok());
assert!(Cli::try_parse_from(["majordomus", "commit", "validate", "m.txt", "--rev", "HEAD"])
.is_err());Variants§
Plan
What the working tree would commit: branch, upstream, divergence, every staged, unstaged and untracked path, any merge or rebase in progress, and the commits the history’s own scoping supports — under a fingerprint that makes the plan refusable once the tree moves
Scopes
Every scope this repository’s commit history uses, how often, and the directories each one is written about
History
Judge every commit in a range of history against the commit policy, in one pass; exit 10 when any carries an error
Fields
Validate
Judge one commit message against the repository’s commit policy; exit 10 when a finding is an error
Trait Implementations§
Source§impl Debug for CommitCommand
impl Debug for CommitCommand
Source§impl FromArgMatches for CommitCommand
impl FromArgMatches for CommitCommand
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§fn update_from_arg_matches_mut<'b>(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut<'b>( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§impl Subcommand for CommitCommand
impl Subcommand for CommitCommand
Source§fn augment_subcommands<'b>(__clap_app: Command) -> Command
fn augment_subcommands<'b>(__clap_app: Command) -> Command
Source§fn augment_subcommands_for_update<'b>(__clap_app: Command) -> Command
fn augment_subcommands_for_update<'b>(__clap_app: Command) -> Command
Command] so it can instantiate self via
[FromArgMatches::update_from_arg_matches_mut] Read moreSource§fn has_subcommand(__clap_name: &str) -> bool
fn has_subcommand(__clap_name: &str) -> bool
Self can parse a specific subcommand