use std::path::PathBuf;
use pound::{
Parse,
ValueEnum,
complete::{
Candidate,
Partial,
},
};
#[derive(Parse)]
#[pound(name = "keyring", version = "0.1.0")]
struct Keyring {
#[pound(short, long, global, default = "secrets.nix")]
file: PathBuf,
#[pound(subcommand)]
cmd: Cmd,
}
#[derive(Parse)]
enum Cmd {
Open {
#[pound(complete = secrets)]
secret: String,
#[pound(long, default = "raw")]
format: Format,
},
Rekey,
}
#[derive(ValueEnum)]
enum Format {
Raw,
#[pound(alias = "js")]
Json,
}
fn secrets(partial: &Partial<'_, '_>, _typed: &str) -> Vec<Candidate> {
let file = partial
.arg("--file")
.and_then(|file| file.last())
.unwrap_or("secrets.nix");
["db-password", "api-token"]
.into_iter()
.map(|name| Candidate::new(name).help(format!("from {file}")))
.collect()
}
fn main() {
caress::handle(Keyring::SPEC);
let _keyring = Keyring::parse();
}