greentic_dev/
secrets_cli.rs

1use std::path::PathBuf;
2use std::process::{Command, Stdio};
3
4use anyhow::{Context, Result, bail};
5use clap::{Args, Subcommand};
6
7#[derive(Subcommand, Debug)]
8pub enum SecretsCommand {
9    /// Delegate to greentic-secrets to initialize secrets for a pack
10    Init(SecretsInitArgs),
11}
12
13#[derive(Args, Debug, Clone)]
14pub struct SecretsInitArgs {
15    /// Path to the pack (.gtpack) to initialize
16    #[arg(short = 'p', long = "pack")]
17    pub pack: PathBuf,
18    /// Optional extra args passed through to greentic-secrets (add `--` before flags)
19    #[arg(last = true)]
20    pub passthrough: Vec<String>,
21}
22
23pub fn run_secrets_command(cmd: SecretsCommand) -> Result<()> {
24    match cmd {
25        SecretsCommand::Init(args) => run_init(&args),
26    }
27}
28
29fn run_init(args: &SecretsInitArgs) -> Result<()> {
30    let mut command = Command::new("greentic-secrets");
31    command
32        .arg("init")
33        .arg("--pack")
34        .arg(&args.pack)
35        .args(&args.passthrough)
36        .stdin(Stdio::inherit())
37        .stdout(Stdio::inherit())
38        .stderr(Stdio::inherit());
39
40    let status = command
41        .status()
42        .with_context(|| "failed to execute greentic-secrets (is it on PATH?)")?;
43    if !status.success() {
44        bail!("greentic-secrets exited with status {}", status);
45    }
46    Ok(())
47}