vmm: Fix --platform syntax with optional feature flags

The `--platform` help string was hardcoded and did not reflect which
optional features (tdx, sev_snp) were actually enabled in. Build the
syntax string dynamically as `PlatformConfig::syntax()`, conditionally
appending feature-gated options so the CLI help stays accurate.

Signed-off-by: Bo Chen <bchen@crusoe.ai>
This commit is contained in:
Bo Chen
2025-08-19 21:35:22 +00:00
parent de601c5eaa
commit 7f377eadd9
2 changed files with 28 additions and 3 deletions
+25
View File
@@ -9,6 +9,7 @@ use std::fs;
use std::path::PathBuf;
use std::result;
use std::str::FromStr;
use std::sync::LazyLock;
use block::ImageType;
use clap::ArgMatches;
@@ -798,6 +799,30 @@ impl PciSegmentConfig {
}
impl PlatformConfig {
pub fn syntax() -> &'static str {
static SYNTAX: LazyLock<String> = LazyLock::new(|| {
let mut syntax = "Platform configuration parameters \
\"num_pci_segments=<num_pci_segments>,iommu_segments=<list_of_segments>,\
iommu_address_width=<bits>,serial_number=<dmi_device_serial_number>,\
uuid=<dmi_device_uuid>,oem_strings=<list_of_strings>"
.to_string();
if cfg!(feature = "tdx") {
syntax.push_str(",tdx=on|off");
}
if cfg!(feature = "sev_snp") {
syntax.push_str(",sev_snp=on|off");
}
syntax.push('"');
syntax
});
&SYNTAX
}
pub fn parse(platform: &str) -> Result<Self> {
let mut parser = OptionParser::new();
parser