use std::path::PathBuf;
use clap::{Args, Parser, Subcommand, ValueEnum};
#[derive(Debug, Parser)]
#[command(
name = "appimg",
version,
about,
long_about = "Installs AppImages into the user's home: the binary goes to \
$XDG_DATA_HOME/appimages, icons into the hicolor theme and a desktop \
entry into $XDG_DATA_HOME/applications. Without a subcommand the \
terminal interface starts.\n\n\
Exit codes: 0 success, 1 error, 2 usage error, 3 nothing to do.",
disable_help_subcommand = true
)]
pub struct Cli {
#[arg(long, global = true)]
pub no_color: bool,
#[arg(short = 'y', long, global = true)]
pub yes: bool,
#[command(subcommand)]
pub command: Option<Command>,
}
#[derive(Debug, Subcommand)]
pub enum Command {
Install(InstallArgs),
List(ListArgs),
Update(UpdateArgs),
UpdateSource(UpdateSourceArgs),
Remove(RemoveArgs),
Edit(EditArgs),
Doctor,
Completions(CompletionsArgs),
}
#[derive(Debug, Args)]
pub struct InstallArgs {
pub source: String,
#[arg(long)]
pub name: Option<String>,
#[arg(long)]
pub comment: Option<String>,
#[arg(long, value_delimiter = ',')]
pub categories: Vec<String>,
#[arg(long = "args", allow_hyphen_values = true)]
pub args: Option<String>,
#[arg(long)]
pub terminal: bool,
#[arg(long)]
pub icon: Option<PathBuf>,
#[arg(long, value_name = "URL|github:owner/repo")]
pub update_source: Option<String>,
#[arg(long)]
pub dry_run: bool,
}
#[derive(Debug, Args)]
pub struct ListArgs {
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Args)]
#[command(group = clap::ArgGroup::new("target").args(["name", "all"]).required(true))]
pub struct UpdateArgs {
pub name: Option<String>,
#[arg(long)]
pub all: bool,
#[arg(long)]
pub check: bool,
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Args)]
pub struct UpdateSourceArgs {
pub name: String,
#[arg(value_name = "URL|github:owner/repo")]
pub source: Option<String>,
#[arg(long, conflicts_with = "source")]
pub clear: bool,
}
#[derive(Debug, Args)]
pub struct RemoveArgs {
pub name: String,
}
#[derive(Debug, Args)]
pub struct EditArgs {
pub name: String,
}
#[derive(Debug, Args)]
pub struct CompletionsArgs {
pub shell: Shell,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum Shell {
Fish,
Bash,
Zsh,
Elvish,
}
impl From<Shell> for clap_complete::Shell {
fn from(shell: Shell) -> Self {
match shell {
Shell::Fish => clap_complete::Shell::Fish,
Shell::Bash => clap_complete::Shell::Bash,
Shell::Zsh => clap_complete::Shell::Zsh,
Shell::Elvish => clap_complete::Shell::Elvish,
}
}
}