]> quire.kejadlen.dev Git - quire.git/commitdiff
Restrict hook subcommand to HookName enum
authorAlpha Chen <alpha@kejadlen.dev>
Sat, 25 Apr 2026 13:36:03 +0000 (06:36 -0700)
committerAlpha Chen <alpha@kejadlen.dev>
Sat, 25 Apr 2026 13:45:59 +0000 (06:45 -0700)
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
src/bin/quire/commands/hook.rs
src/bin/quire/main.rs

index 17c5fb2d1595e875d35e2da23190d05ddf06c467..a4bc75639e1affd7a8b0e8518780bac944facd1a 100644 (file)
@@ -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(())
 }
index 5ab7114434c71d84f74f6a8caa9e02d40373da1c..4a53d44d6879d9cd543b6fcd3e5d9f86c4b39cd4 100644 (file)
@@ -40,8 +40,8 @@ enum Commands {
 
     /// Invoked by git hooks configured via hook.<name>.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(())