From df8854ff84f2d7c6aa8901be95ac565009194eb9 Mon Sep 17 00:00:00 2001 From: Noor Date: Wed, 16 Jul 2025 18:34:24 +0530 Subject: [PATCH] update CLI argument for vm deploy port exposure Adds conflict rules to prevent using `--public-ip` and `--expose-port` at the same time. --- src/bin/detee-cli.rs | 14 +++++++++++++- src/snp/cli_handler.rs | 7 ++++++- src/snp/deploy.rs | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/bin/detee-cli.rs b/src/bin/detee-cli.rs index 1346841..08d0b1f 100644 --- a/src/bin/detee-cli.rs +++ b/src/bin/detee-cli.rs @@ -148,7 +148,8 @@ fn clap_cmd() -> Command { ) .arg( Arg::new("port") - .long("port") + .short('p') + .long("expose-port") .value_parser(clap::value_parser!(u32).range(0..65535)) .action(clap::ArgAction::Append) .help("Application exposing port") @@ -394,6 +395,17 @@ fn clap_cmd() -> Command { .long("public-ip") .help("get a public IPv4 address for this VM") .action(clap::ArgAction::SetTrue) + .conflicts_with("port") + ) + .arg( + Arg::new("port") + .short('p') + .long("expose-port") + .value_parser(clap::value_parser!(u32).range(0..65535)) + .action(clap::ArgAction::Append) + .help("vm exposing port") + .long_help("Port to expose on the vm which mapped into the host's public IP's port") + .conflicts_with("public-ip") ) ) .subcommand(Command::new("inspect").about("list all available information about a VM") diff --git a/src/snp/cli_handler.rs b/src/snp/cli_handler.rs index 129ca42..732e7ef 100644 --- a/src/snp/cli_handler.rs +++ b/src/snp/cli_handler.rs @@ -63,8 +63,13 @@ fn handle_vm_deploy(matches: &ArgMatches) -> Result("location").unwrap().as_str(); let ipv4: crate::snp::deploy::IPv4Config = match matches.get_one::("public-ip").unwrap() { true => crate::snp::deploy::IPv4Config::PublicIPv4, - false => crate::snp::deploy::IPv4Config::PublishPorts(Vec::new()), + false => { + let exposing_port = + matches.get_many::("port").unwrap_or_default().cloned().collect::>(); + crate::snp::deploy::IPv4Config::PublishPorts(exposing_port) + } }; + let distro = crate::snp::Distro::from_string(matches.get_one::("distribution").unwrap()); let vm_config = snp::deploy::Request { diff --git a/src/snp/deploy.rs b/src/snp/deploy.rs index 7d4dca6..da6925f 100644 --- a/src/snp/deploy.rs +++ b/src/snp/deploy.rs @@ -9,7 +9,7 @@ use crate::utils::block_on; use log::{debug, info}; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub enum IPv4Config { PublishPorts(Vec), PublicIPv4,