greentic_dev/
secrets_cli.rs1use std::ffi::OsString;
2use std::path::PathBuf;
3
4use anyhow::{Context, Result, bail};
5use clap::{Args, Subcommand};
6
7use crate::i18n;
8use crate::passthrough::{resolve_binary, run_passthrough};
9
10#[derive(Subcommand, Debug)]
11pub enum SecretsCommand {
12 Init(SecretsInitArgs),
14}
15
16#[derive(Args, Debug, Clone)]
17pub struct SecretsInitArgs {
18 #[arg(short = 'p', long = "pack")]
20 pub pack: PathBuf,
21 #[arg(last = true)]
23 pub passthrough: Vec<String>,
24}
25
26pub fn run_secrets_command(cmd: SecretsCommand, locale: &str) -> Result<()> {
27 match cmd {
28 SecretsCommand::Init(args) => run_init(&args, locale),
29 }
30}
31
32fn run_init(args: &SecretsInitArgs, locale: &str) -> Result<()> {
33 let bin = resolve_binary("greentic-secrets")?;
34 let mut argv = vec![
35 OsString::from("init"),
36 OsString::from("--pack"),
37 args.pack.clone().into_os_string(),
38 ];
39 argv.extend(args.passthrough.iter().map(OsString::from));
40 let status = run_passthrough(&bin, &argv, false)
41 .with_context(|| i18n::t(locale, "runtime.secrets.error.execute"))?;
42 if !status.success() {
43 bail!(
44 "{}",
45 i18n::tf(
46 locale,
47 "runtime.secrets.error.exit_status",
48 &[("status", status.to_string())],
49 )
50 );
51 }
52 Ok(())
53}