Skip to main content

envvault/cli/commands/
get.rs

1//! `envvault get` — retrieve and print a single secret's value.
2
3use crate::cli::{load_keyfile, prompt_password_for_vault, vault_path, Cli};
4use crate::errors::Result;
5use crate::vault::VaultStore;
6
7/// Execute the `get` command.
8pub fn execute(cli: &Cli, key: &str) -> Result<()> {
9    let path = vault_path(cli)?;
10    let keyfile = load_keyfile(cli)?;
11
12    // Open the vault (requires password).
13    let vault_id = path.to_string_lossy();
14    let password = prompt_password_for_vault(Some(&vault_id))?;
15    let store = VaultStore::open(&path, password.as_bytes(), keyfile.as_deref())?;
16
17    // Decrypt and print the secret value to stdout.
18    let value = store.get_secret(key)?;
19    println!("{value}");
20
21    Ok(())
22}