1use std::{fmt::Debug, path::PathBuf};
2
3use clap::Parser;
4use miette::{miette, Result};
5
6use crate::{
7 files::{decrypt_file, remove_age_ext},
8 keys::KeyArgs,
9};
10
11#[derive(Debug, Clone, Parser)]
17pub struct DecryptArgs {
18 pub input: PathBuf,
20
21 #[arg(short, long)]
26 pub output: Option<PathBuf>,
27
28 #[command(flatten)]
29 #[allow(missing_docs, reason = "don't interfere with clap")]
30 pub key: KeyArgs,
31}
32
33pub async fn run(
35 DecryptArgs {
36 ref input,
37 output,
38 key,
39 }: DecryptArgs,
40) -> Result<()> {
41 let secret_key = key.require_secret_key().await?;
42 let output = if let Some(ref path) = output {
43 path.to_owned()
44 } else {
45 remove_age_ext(input)
46 .map_err(|_| miette!("Cannot guess output path, use --output to set one"))?
47 };
48
49 decrypt_file(input, output, secret_key).await?;
50 Ok(())
51}