use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser)]
#[command(name = "portablesource")]
#[command(about = "PortableSource - Portable AI/ML Environment Manager")]
#[command(version = env!("CARGO_PKG_VERSION"))]
pub struct Cli {
#[arg(long)]
pub debug: bool,
#[arg(long)]
pub install_path: Option<PathBuf>,
#[command(subcommand)]
pub command: Option<Commands>,
}
#[derive(Subcommand)]
pub enum Commands {
SetupEnv,
#[cfg(unix)]
SetupReg,
#[cfg(unix)]
Unregister,
#[cfg(unix)]
Uninstall,
#[cfg(unix)]
ChangePath,
#[command(alias = "ir")]
InstallRepo {
repo: String,
#[arg(long)]
python_ver: Option<String>,
},
#[command(alias = "ur")]
UpdateRepo {
repo: Option<String>,
},
#[command(alias = "dr")]
DeleteRepo {
repo: String,
},
#[command(alias = "lr")]
ListRepos,
#[command(alias = "rr")]
RunRepo {
repo: String,
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
SystemInfo,
CheckEnv,
#[cfg(windows)]
InstallMsvc,
#[cfg(windows)]
CheckMsvc,
CheckGpu,
Version,
#[cfg(windows)]
#[command(alias = "set-version")]
SetVersion {
version: String,
},
#[cfg(windows)]
Pack {
repo: String,
},
}
impl Cli {
pub fn parse_args() -> Self {
Self::parse()
}
pub fn has_command(&self) -> bool {
self.command.is_some()
}
pub fn get_command(&self) -> &Commands {
self.command.as_ref().unwrap_or(&Commands::SystemInfo)
}
}