// SPDX-License-Identifier: MIT
//
// Copyright IBM Corp.

use std::path::PathBuf;
use std::sync::OnceLock;

use clap::{ArgAction, Parser, ValueHint};

static VERSION: OnceLock<String> = OnceLock::new();

/// The pvebc command processes an AddSecretRequest file (toc.asr) that defines the root of EBC
/// resources. It validates references to the associated toc.pol policy and manages their addition,
/// with options for verification and dry-run execution.
#[derive(Parser)]
#[command(long_version=ver(), disable_version_flag(true))]
pub struct Cli {
    /// Print version information and exit.
    #[arg(long, action=ArgAction::Version)]
    version: (),

    /// Specifies the toc.asr which is the root of the EBC resources
    ///
    /// Specify the add-secret request file toc.asr that serves as the root of the EBC resources.
    /// Its user data must contain a reference to toc.pol as generated by pvsecret with the
    /// --policy option.
    #[arg(short, long, value_name = "FILE", value_hint = ValueHint::FilePath)]
    pub toc: PathBuf,

    /// Prevents adding of the AddSecretRequest
    ///
    /// Do not add the AddSecretRequest. Use this option to validate a generated policy. It can be
    /// run on a non-SEL guest to verify ASR-to-policy links and the associated policy  toc.pol.
    #[arg(long)]
    pub dry_run: bool,
}

fn ver() -> &'static str {
    VERSION.get_or_init(|| utils::tools_version_fmt!(2026))
}
