From: Alpha Chen Date: Sat, 25 Apr 2026 13:36:03 +0000 (-0700) Subject: Restrict hook subcommand to HookName enum X-Git-Url: http://quire.kejadlen.dev/?a=commitdiff_plain;h=f2611b499731471a608343437217d20587785550;p=quire.git Restrict hook subcommand to HookName enum Only post-receive is allowed for now; clap rejects anything else at parse time. Easy to extend with more variants later. Assisted-by: GLM-5.1 via pi --- diff --git a/src/bin/quire/commands/hook.rs b/src/bin/quire/commands/hook.rs index 17c5fb2..a4bc756 100644 --- a/src/bin/quire/commands/hook.rs +++ b/src/bin/quire/commands/hook.rs @@ -1,6 +1,20 @@ use miette::Result; -pub async fn run(hook_name: &str) -> Result<()> { +#[derive(Clone, Copy, Debug, clap::ValueEnum)] +pub enum HookName { + PostReceive, +} + +impl std::fmt::Display for HookName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let name = match self { + HookName::PostReceive => "post-receive", + }; + f.write_str(name) + } +} + +pub async fn run(hook_name: HookName) -> Result<()> { tracing::info!(hook = %hook_name, "hook invoked"); Ok(()) } diff --git a/src/bin/quire/main.rs b/src/bin/quire/main.rs index 5ab7114..4a53d44 100644 --- a/src/bin/quire/main.rs +++ b/src/bin/quire/main.rs @@ -40,8 +40,8 @@ enum Commands { /// Invoked by git hooks configured via hook..command. Hook { - /// The hook name (e.g. pre-receive, post-receive). - hook_name: String, + /// The hook name (e.g. post-receive). + hook_name: crate::commands::hook::HookName, }, } @@ -69,7 +69,7 @@ async fn main() -> Result<()> { match command { Commands::Serve => commands::serve::run(&config).await?, Commands::Exec { command } => commands::exec::run(&config, command).await?, - Commands::Hook { hook_name } => commands::hook::run(&hook_name).await?, + Commands::Hook { hook_name } => commands::hook::run(hook_name).await?, } Ok(())