mod backend;
mod commands;
mod engine;
mod model;
mod tui;
use clap::{Parser, Subcommand};
const EXAMPLES: &str = concat!(
"\x1b[1mExamples:\x1b[0m
whypkg Browse every installed package
whypkg --upgradable Browse only packages with a pending upgrade
whypkg pending Report every pending upgrade, grouped by why it's here
whypkg pending --quick One line per pending package: size + reason
whypkg self update Reinstall the latest release from crates.io
whypkg self check Ask crates.io whether a newer release exists
Inside the browser: type to filter, Enter to open, Esc to go back.",
"\n\n",
env!("CARGO_PKG_REPOSITORY"),
"\ncontributors: ",
env!("CARGO_PKG_AUTHORS"),
);
const LONG_VERSION: &str = concat!(
env!("CARGO_PKG_VERSION"),
"\n",
env!("CARGO_PKG_LICENSE"),
" ",
env!("CARGO_PKG_REPOSITORY"),
"\ncontributors: ",
env!("CARGO_PKG_AUTHORS"),
);
#[derive(Parser)]
#[command(
name = "whypkg",
bin_name = "whypkg",
version,
long_version = LONG_VERSION,
about,
after_help = EXAMPLES,
)]
struct Cli {
#[command(subcommand)]
command: Option<Cmd>,
#[arg(long, global = true)]
upgradable: bool,
}
#[derive(Subcommand)]
enum Cmd {
Pending(commands::pending::Args),
#[command(name = "self", subcommand)]
Selfie(commands::selfcmd::Cmd),
}
#[cfg(unix)]
fn restore_sigpipe() {
unsafe {
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
}
}
#[cfg(not(unix))]
fn restore_sigpipe() {}
fn main() {
restore_sigpipe();
let cli = Cli::parse();
match cli.command {
Some(Cmd::Pending(args)) => commands::pending::run(args),
Some(Cmd::Selfie(cmd)) => commands::selfcmd::run(cmd),
None => commands::browse::run(commands::browse::Args {
upgradable: cli.upgradable,
}),
}
}