add a fallback for the --fingerprint argument

Fallback to the PBS_FINGERPRINT environment variable if the
--fingerprint argument is not specified.

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
This commit is contained in:
Filip Schauer 2024-04-09 14:14:19 +02:00 committed by Wolfgang Bumiller
parent 68e1a2e7c8
commit 0d40a7001d
2 changed files with 4 additions and 3 deletions

View File

@ -7,7 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
bincode = "1.3" bincode = "1.3"
clap = { version = "4.0.32", features = ["cargo"] } clap = { version = "4.0.32", features = ["cargo", "env"] }
md5 = "0.7.0" md5 = "0.7.0"
scopeguard = "1.1.0" scopeguard = "1.1.0"
serde = "1.0" serde = "1.0"

View File

@ -27,7 +27,7 @@ fn main() -> Result<()> {
.long("fingerprint") .long("fingerprint")
.value_name("FINGERPRINT") .value_name("FINGERPRINT")
.help("Proxmox Backup Server Fingerprint") .help("Proxmox Backup Server Fingerprint")
.required(true), .env("PBS_FINGERPRINT"),
) )
.arg( .arg(
Arg::new("keyfile") Arg::new("keyfile")
@ -72,9 +72,10 @@ fn main() -> Result<()> {
let pbs_repository = matches.get_one::<String>("repository").unwrap().to_string(); let pbs_repository = matches.get_one::<String>("repository").unwrap().to_string();
let vmid = matches.get_one::<String>("vmid").unwrap().to_string(); let vmid = matches.get_one::<String>("vmid").unwrap().to_string();
let fingerprint = matches let fingerprint = matches
.get_one::<String>("fingerprint") .get_one::<String>("fingerprint")
.unwrap() .context("Fingerprint not set. Use $PBS_FINGERPRINT or --fingerprint")?
.to_string(); .to_string();
let keyfile = matches.get_one::<String>("keyfile"); let keyfile = matches.get_one::<String>("keyfile");