Skip to main content

auths_cli/commands/
approval.rs

1//! CLI command for approval management.
2
3use anyhow::Result;
4use clap::{Parser, Subcommand};
5
6use crate::commands::executable::ExecutableCommand;
7use crate::config::CliConfig;
8
9/// Exit code when a command's policy evaluation returns RequiresApproval.
10/// Value 75 = EX_TEMPFAIL (sysexits.h) — "temporary failure, try again later."
11pub const EXIT_APPROVAL_REQUIRED: i32 = 75;
12
13#[derive(Parser, Debug)]
14#[command(about = "Manage approval gates")]
15pub struct ApprovalCommand {
16    #[command(subcommand)]
17    pub command: ApprovalSubcommand,
18}
19
20#[derive(Subcommand, Debug)]
21pub enum ApprovalSubcommand {
22    /// List pending approval requests.
23    List(ApprovalListCommand),
24    /// Grant approval for a pending request.
25    Grant(ApprovalGrantCommand),
26}
27
28#[derive(Parser, Debug)]
29pub struct ApprovalListCommand {}
30
31#[derive(Parser, Debug)]
32pub struct ApprovalGrantCommand {
33    /// The request hash to approve (hex-encoded).
34    #[arg(long)]
35    pub request: String,
36    /// Optional note for the approval.
37    #[arg(long)]
38    pub note: Option<String>,
39}
40
41impl ExecutableCommand for ApprovalCommand {
42    fn execute(&self, _ctx: &CliConfig) -> Result<()> {
43        match &self.command {
44            ApprovalSubcommand::List(_cmd) => {
45                println!("No pending approval requests.");
46                Ok(())
47            }
48            ApprovalSubcommand::Grant(cmd) => {
49                println!(
50                    "Approval grant for request {} — not yet wired to storage backend.",
51                    cmd.request
52                );
53                Ok(())
54            }
55        }
56    }
57}