rustpm 0.2.6

A fast, friendly APT frontend with kernel, desktop, and sources management
use clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
#[command(name = "rustpm", about = "A fast, friendly APT frontend with kernel management")]
pub struct Cli {
    #[command(subcommand)]
    pub command: Option<Commands>,

    /// Disable TUI and use plain text output
    #[arg(long, global = true, env = "RUSTPM_NO_TUI")]
    pub no_tui: bool,

    /// Disable self-update check
    #[arg(long, global = true, env = "RUSTPM_NO_UPDATE_CHECK")]
    pub no_update_check: bool,

    /// Enable verbose logging
    #[arg(short, long, global = true)]
    pub verbose: bool,
}

#[derive(Subcommand, Debug)]
pub enum Commands {
    /// Fetch updated package lists
    Update,

    /// Upgrade installed packages
    Upgrade {
        /// Perform a full-upgrade (may remove packages)
        #[arg(long)]
        full: bool,
    },

    /// Install one or more packages
    Install {
        packages: Vec<String>,
    },

    /// Remove one or more packages
    Remove {
        packages: Vec<String>,
        /// Also remove configuration files
        #[arg(long)]
        purge: bool,
    },

    /// Remove packages and their configuration files
    Purge {
        packages: Vec<String>,
    },

    /// Search for packages
    Search {
        term: String,
        /// Match package names only (not descriptions)
        #[arg(long)]
        names_only: bool,
    },

    /// Show details for a package
    Show {
        package: String,
    },

    /// List packages
    List {
        /// Only show installed packages
        #[arg(long)]
        installed: bool,
        /// Only show upgradable packages
        #[arg(long)]
        upgradable: bool,
    },

    /// View and manage transaction history
    History {
        #[command(subcommand)]
        action: Option<HistoryCommands>,
        /// Maximum number of entries to show
        #[arg(long, default_value = "20")]
        limit: usize,
    },

    /// Manage Linux kernels
    Kernel {
        #[command(subcommand)]
        action: KernelCommands,
    },

    /// Manage desktop environments
    Desktop {
        #[command(subcommand)]
        action: DesktopCommands,
    },

    /// Manage APT sources
    Sources {
        #[command(subcommand)]
        action: SourcesCommands,
    },
}

#[derive(Subcommand, Debug)]
pub enum HistoryCommands {
    /// Undo a transaction by ID
    Undo { id: u64 },
}

#[derive(Subcommand, Debug)]
pub enum KernelCommands {
    /// List installed and available kernels
    List,

    /// Install a Debian kernel by version
    Install { version: String },

    /// Remove a Debian kernel by version
    Remove { version: String },

    /// Upgrade to the latest available Debian kernel
    Update,

    /// Pin (hold) a kernel at its current version
    Pin { version: String },

    /// Unpin (unhold) a kernel
    Unpin { version: String },

    /// Manage vanilla (mainline) kernels from kernel.org
    Vanilla {
        #[command(subcommand)]
        action: VanillaCommands,
    },
}

#[derive(Subcommand, Debug)]
pub enum VanillaCommands {
    /// List available vanilla kernel releases
    List {
        /// Show only stable releases
        #[arg(long)]
        stable: bool,
        /// Show only mainline (rc) releases
        #[arg(long)]
        mainline: bool,
        /// Show only longterm releases
        #[arg(long)]
        longterm: bool,
    },

    /// Download and install a vanilla kernel
    Install { version: String },

    /// Remove a vanilla kernel
    Remove { version: String },

    /// Show details for a vanilla kernel release
    Info { version: String },
}

#[derive(Subcommand, Debug)]
pub enum DesktopCommands {
    /// List available desktop environments
    List,

    /// Install a desktop environment
    Install { name: String },

    /// Remove a desktop environment
    Remove { name: String },

    /// Switch default display manager to a desktop environment's DM
    Switch { name: String },
}

#[derive(Subcommand, Debug)]
pub enum SourcesCommands {
    /// List configured APT sources
    List,

    /// Add a new APT source
    Add {
        uri: String,
        suite: String,
        components: Vec<String>,
    },

    /// Remove an APT source by URI
    Remove { uri: String },

    /// Enable a disabled APT source
    Enable { uri: String },

    /// Disable (comment out) an APT source
    Disable { uri: String },

    /// Open sources.list in $EDITOR
    Edit,
}