update CLI argument for vm deploy port exposure

Adds conflict rules to prevent using `--public-ip` and `--expose-port` at the same time.
This commit is contained in:
Noor 2025-07-16 18:34:24 +05:30
parent 006817161d
commit df8854ff84
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146
3 changed files with 20 additions and 3 deletions

@ -148,7 +148,8 @@ fn clap_cmd() -> Command {
) )
.arg( .arg(
Arg::new("port") Arg::new("port")
.long("port") .short('p')
.long("expose-port")
.value_parser(clap::value_parser!(u32).range(0..65535)) .value_parser(clap::value_parser!(u32).range(0..65535))
.action(clap::ArgAction::Append) .action(clap::ArgAction::Append)
.help("Application exposing port") .help("Application exposing port")
@ -394,6 +395,17 @@ fn clap_cmd() -> Command {
.long("public-ip") .long("public-ip")
.help("get a public IPv4 address for this VM") .help("get a public IPv4 address for this VM")
.action(clap::ArgAction::SetTrue) .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") .subcommand(Command::new("inspect").about("list all available information about a VM")

@ -63,8 +63,13 @@ fn handle_vm_deploy(matches: &ArgMatches) -> Result<snp::VmSshArgs, Box<dyn Erro
let location = matches.get_one::<String>("location").unwrap().as_str(); let location = matches.get_one::<String>("location").unwrap().as_str();
let ipv4: crate::snp::deploy::IPv4Config = match matches.get_one::<bool>("public-ip").unwrap() { let ipv4: crate::snp::deploy::IPv4Config = match matches.get_one::<bool>("public-ip").unwrap() {
true => crate::snp::deploy::IPv4Config::PublicIPv4, true => crate::snp::deploy::IPv4Config::PublicIPv4,
false => crate::snp::deploy::IPv4Config::PublishPorts(Vec::new()), false => {
let exposing_port =
matches.get_many::<u32>("port").unwrap_or_default().cloned().collect::<Vec<_>>();
crate::snp::deploy::IPv4Config::PublishPorts(exposing_port)
}
}; };
let distro = let distro =
crate::snp::Distro::from_string(matches.get_one::<String>("distribution").unwrap()); crate::snp::Distro::from_string(matches.get_one::<String>("distribution").unwrap());
let vm_config = snp::deploy::Request { let vm_config = snp::deploy::Request {

@ -9,7 +9,7 @@ use crate::utils::block_on;
use log::{debug, info}; use log::{debug, info};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize, Debug)]
pub enum IPv4Config { pub enum IPv4Config {
PublishPorts(Vec<u32>), PublishPorts(Vec<u32>),
PublicIPv4, PublicIPv4,