porta-rs 0.1.1

Zero-trust CGNAT bypass via WireGuard tunnel
pub mod add_port;
pub mod logs;
pub mod metrics;
pub mod remove_port;
pub mod run;
pub mod setup;
pub mod status;

use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(
    name = "porta",
    about = "Zero-trust CGNAT bypass via WireGuard tunnel",
    version,
    long_about = "Porta allows machines behind CGNAT to expose services via a WireGuard tunnel to a machine with a public IP."
)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
    /// Interactive setup wizard
    Setup(setup::SetupArgs),

    /// Add a port forwarding rule
    AddPort(add_port::AddPortArgs),

    /// Remove a port forwarding rule
    RemovePort(remove_port::RemovePortArgs),

    /// List all port forwarding rules
    Status(status::StatusArgs),

    /// Show metrics and traffic statistics
    Metrics(metrics::MetricsArgs),

    /// View logs
    Logs(logs::LogsArgs),

    /// Run the porta service
    Run(run::RunArgs),
}

impl Cli {
    pub async fn execute(&self) -> anyhow::Result<()> {
        match &self.command {
            Commands::Setup(args) => setup::execute(args),
            Commands::AddPort(args) => add_port::execute(args),
            Commands::RemovePort(args) => remove_port::execute(args),
            Commands::Status(args) => status::execute(args),
            Commands::Metrics(args) => metrics::execute(args),
            Commands::Logs(args) => logs::execute(args),
            Commands::Run(args) => run::execute(args).await,
        }
    }
}