use clap::{Parser, Subcommand, ValueEnum};
#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum SourceScope {
Aur,
Repo,
Repos,
}
#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompletionShell {
Bash,
Zsh,
Fish,
}
#[derive(Parser, Debug)]
#[command(
name = "haj",
author = "asitos",
version,
about = "the beautiful, cross-distro package manager and tui.",
long_about = None,
disable_version_flag = true,
help_template = "\
{about}
Usage: \x1b[36;1mhaj\x1b[0m [OPTIONS] <COMMAND>
Commands (alias):
\x1b[36;1mtui (t)\x1b[0m launch the interactive tui dashboard
\x1b[36;1mupdate (sync/up)\x1b[0m synchronize remote repositories
\x1b[36;1mupgrade (jump)\x1b[0m [pkg] upgrade system or packages [--no-sync]
\x1b[36;1minstall/add (i/a)\x1b[0m <pkg|file> install packages or local archive
\x1b[36;1mremove (rm/toss)\x1b[0m <pkg> remove packages & unneeded deps
\x1b[36;1msearch (s/find)\x1b[0m <query> search repositories & external
\x1b[36;1mshow (info/about)\x1b[0m <pkg> show detailed package information
\x1b[36;1mgroup (g)\x1b[0m <name> browse & install package groups
\x1b[36;1mlist (ls)\x1b[0m [filter] list (explicit|deps|aur|orphans|updates)
\x1b[36;1mstats (st)\x1b[0m show system health and statistics
\x1b[36;1mload (l)\x1b[0m <path> install a local package archive
\x1b[36;1mfetch (f/get)\x1b[0m <pkg> download packages without installing
\x1b[36;1mdowngrade (sink)\x1b[0m <pkg> [ver] downgrade an installed package
\x1b[36;1mowns (ow/which)\x1b[0m <path> find which package owns a file
\x1b[36;1mfiles (lf)\x1b[0m [in|of] <pkg> list files owned by a package
\x1b[36;1mlocate (loc/where)\x1b[0m <query> search repositories for a file
\x1b[36;1mhistory (h)\x1b[0m [-l <n>] show recent package transactions
\x1b[36;1morphan (o/prune)\x1b[0m list or prune orphaned dependencies
\x1b[36;1mclean (c)\x1b[0m [cache|orphans] clean cache [-k <n>] or orphans
\x1b[36;1mmark (m)\x1b[0m <pkg> [as exp|dep] set or toggle package install reason
\x1b[36;1mdiff (pn/merge)\x1b[0m interactively merge config files
\x1b[36;1mpkgbuild (pb)\x1b[0m <pkg> inspect PKGBUILD of an AUR package
Options:
{options}
run 'haj <cmd> --help' for subcommands, or 'man haj' for all aliases & docs."
)]
#[command(
name = "haj",
version,
about = "the beautiful, cross-distro package manager and tui."
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
#[arg(short = 'a', long, global = true)]
pub aur: bool,
#[arg(short = 'r', long, global = true)]
pub repo: bool,
#[arg(
long,
global = true,
value_enum,
hide_possible_values = true,
value_name = "SOURCE"
)]
pub from: Option<SourceScope>,
#[arg(short = 'y', long, global = true)]
pub noconfirm: bool,
#[arg(short = 'n', long, global = true)]
pub needed: bool,
#[arg(
short = 'i',
long,
global = true,
value_delimiter = ',',
value_name = "PKG"
)]
pub ignore: Vec<String>,
#[arg(short = 'c', long, global = true, value_name = "PATH")]
pub config: Option<String>,
#[arg(long, global = true, value_name = "PATH")]
pub root: Option<String>,
#[arg(short, long, global = true)]
pub verbose: bool,
#[arg(short = 'd', long, global = true)]
pub dry_run: bool,
#[arg(short = 'V', long, action = clap::ArgAction::Version)]
pub version: Option<bool>,
}
#[derive(Subcommand, Debug, Clone)]
pub enum Commands {
#[command(
alias = "t",
help_template = "\
\x1b[36;1mhaj tui (alias: t)\x1b[0m
Usage: haj tui [OPTIONS]
Description:
launch the interactive package manager terminal dashboard
features stats, search, orphans cleaner, news reader, and transaction history
Options:
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Tui,
#[command(
aliases = ["add", "i", "a"],
help_template = "\
\x1b[36;1mhaj install/add (aliases: i, a)\x1b[0m
Usage: haj install [OPTIONS] <packages>...
Description:
install packages from repositories/AUR or a local package archive
Examples:
haj add neovim
haj add yay-bin from aur
haj add ./foo.pkg.tar.zst
Arguments:
<packages>... list of packages or local archive paths to install
Options:
-a, --aur restrict operations to the aur
-r, --repo restrict operations to arch repositories
--from <SOURCE> restrict operations to 'aur' or 'repo'
-n, --needed do not reinstall up-to-date packages
-i, --ignore <IGNORE> ignore a package upgrade (comma-separated)
-y, --noconfirm bypass all confirmation prompts
--root <PATH> specify an alternate installation root
-v, --verbose enable verbose debug logging
-d, --dry-run preview a command without modifying the system
-h, --help print help"
)]
Install {
#[arg(required = true)]
packages: Vec<String>,
},
#[command(
aliases = ["rm", "toss", "uninstall", "delete", "drop"],
help_template = "\
\x1b[36;1mhaj remove (aliases: rm, toss, uninstall, delete, drop)\x1b[0m
Usage: haj remove [OPTIONS] <packages>...
Description:
remove packages along with their unneeded dependencies (via pacman -Rs)
Arguments:
<packages>... list of packages to remove
Options:
-y, --noconfirm bypass all confirmation prompts
--root <PATH> specify an alternate installation root
-v, --verbose enable verbose debug logging
-d, --dry-run preview a command without modifying the system
-h, --help print help"
)]
Remove {
#[arg(required = true)]
packages: Vec<String>,
},
#[command(
aliases = ["up", "sync", "refresh"],
help_template = "\
\x1b[36;1mhaj update (aliases: up, sync, refresh)\x1b[0m
Usage: haj update [OPTIONS]
Description:
synchronize package databases from remote repositories
Options:
-a, --aur restrict operations to the aur
-r, --repo restrict operations to arch repositories
--root <PATH> specify an alternate installation root
-v, --verbose enable verbose debug logging
-d, --dry-run preview a command without modifying the system
-h, --help print help"
)]
Update,
#[command(
alias = "jump",
help_template = "\
\x1b[36;1mhaj upgrade (alias: jump)\x1b[0m
Usage: haj upgrade [OPTIONS] [packages]...
Description:
perform a full system upgrade or upgrade specific packages
Arguments:
[packages]... optional specific packages to upgrade
Options:
--no-sync do not sync package databases from remote mirrors
-a, --aur restrict operations to the aur
-r, --repo restrict operations to arch repositories
--from <SOURCE> restrict operations to 'aur' or 'repo'
-y, --noconfirm bypass all confirmation prompts
--root <PATH> specify an alternate installation root
-v, --verbose enable verbose debug logging
-d, --dry-run preview a command without modifying the system
-h, --help print help"
)]
Upgrade {
#[arg(long)]
no_sync: bool,
packages: Vec<String>,
},
#[command(
aliases = ["s", "find"],
help_template = "\
\x1b[36;1mhaj search (aliases: s, find)\x1b[0m
Usage: haj search [OPTIONS] <query>
Description:
search official repositories and AUR for matching packages
Arguments:
<query> the search term to query
Options:
-a, --aur restrict operations to the aur
-r, --repo restrict operations to arch repositories
--from <SOURCE> restrict operations to 'aur' or 'repo'
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Search { query: String },
#[command(
aliases = ["info", "about", "describe"],
help_template = "\
\x1b[36;1mhaj show (aliases: info, about, describe)\x1b[0m
Usage: haj show [OPTIONS] <package>
Description:
display detailed package information such as size, installation reason, and dependencies
Arguments:
<package> the package name to inspect
Options:
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Show { package: String },
#[command(
alias = "g",
help_template = "\
\x1b[36;1mhaj group (alias: g)\x1b[0m
Usage: haj group [OPTIONS] <name>
Description:
browse and install packages associated with a package group or meta-package
Arguments:
<name> the package group or meta-package name
Options:
-y, --noconfirm bypass all confirmation prompts
-d, --dry-run preview a command without modifying the system
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Group { name: String },
#[command(
alias = "ls",
help_template = "\
\x1b[36;1mhaj list (alias: ls)\x1b[0m
Usage: haj list [OPTIONS] [filter]
Description:
list installed packages or query subsets (explicit, deps, aur, orphans, updates)
Examples:
haj list explicit
haj list aur
haj list updates
Arguments:
[filter] optional filter word (explicit|deps|aur|foreign|orphans|updates)
Options:
-e, --explicit show only packages installed explicitly
-p, --deps show only packages installed as dependencies
-f, --foreign show only foreign/AUR packages
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
List {
#[arg(short, long)]
explicit: bool,
#[arg(short = 'p', long)]
deps: bool,
#[arg(short = 'f', long)]
foreign: bool,
filter: Option<String>,
},
#[command(
alias = "st",
help_template = "\
\x1b[36;1mhaj stats (alias: st)\x1b[0m
Usage: haj stats [OPTIONS]
Description:
display system health score, disk usage, cache statistics, and package counts
Options:
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Stats,
#[command(
alias = "h",
help_template = "\
\x1b[36;1mhaj history (alias: h)\x1b[0m
Usage: haj history [OPTIONS]
Description:
show recent transaction history (installs, upgrades, removals)
Options:
-l, --limit <LIMIT> number of recent changes to show [default: 50]
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
History {
#[arg(short = 'l', long, default_value_t = 50)]
limit: usize,
},
#[command(
aliases = ["sink", "rollback"],
help_template = "\
\x1b[36;1mhaj downgrade (aliases: sink, rollback)\x1b[0m
Usage: haj downgrade [OPTIONS] <package> [to] [version]
Description:
downgrade an installed package using cached archives
Examples:
haj downgrade bash
haj downgrade bash to 5.2.026-1
Arguments:
<package> the package name to downgrade
[version] optional target version
Options:
-y, --noconfirm bypass all confirmation prompts
--root <PATH> specify an alternate installation root
-v, --verbose enable verbose debug logging
-d, --dry-run preview a command without modifying the system
-h, --help print help"
)]
Downgrade {
package: String,
version: Option<String>,
},
#[command(
alias = "c",
help_template = "\
\x1b[36;1mhaj clean (alias: c)\x1b[0m
Usage: haj clean [OPTIONS] [target]
Description:
clean the package cache (default) or orphaned dependencies
Examples:
haj clean
haj clean cache -k 2
haj clean orphans
Arguments:
[target] optional target: 'cache' (default) or 'orphans'
Options:
-k, --keep <KEEP> number of package versions to keep in cache [default: 3]
-y, --noconfirm bypass all confirmation prompts
-d, --dry-run preview a command without modifying the system
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Clean {
target: Option<String>,
#[arg(short = 'k', long, default_value_t = 3)]
keep: usize,
},
#[command(
aliases = ["o", "orphans", "autoremove", "prune"],
help_template = "\
\x1b[36;1mhaj orphan (aliases: o, orphans, autoremove, prune)\x1b[0m
Usage: haj orphan [OPTIONS]
Description:
detect and optionally remove orphaned package dependencies
Options:
-y, --noconfirm bypass all confirmation prompts
-d, --dry-run preview a command without modifying the system
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Orphan,
#[command(
aliases = ["ow", "owner", "which"],
help_template = "\
\x1b[36;1mhaj owns (aliases: ow, owner, which)\x1b[0m
Usage: haj owns [OPTIONS] <file_path>
Description:
find which installed package owns a given file path ('haj who owns <path>')
Arguments:
<file_path> the file path to query (e.g. /usr/bin/bash)
Options:
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Owns { file_path: String },
#[command(
aliases = ["loc", "where", "find-file"],
help_template = "\
\x1b[36;1mhaj locate (aliases: loc, where, find-file)\x1b[0m
Usage: haj locate [OPTIONS] <query>
Description:
search remote package repositories for a file name matching the query (using pacman -F)
Arguments:
<query> the file name or pattern to search for
Options:
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Locate { query: String },
#[command(
alias = "lf",
help_template = "\
\x1b[36;1mhaj files (alias: lf)\x1b[0m
Usage: haj files [OPTIONS] <package>
Description:
list all files installed by a specific package ('haj list files <pkg>')
Arguments:
<package> the name of the package
Options:
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Files { package: String },
#[command(
alias = "l",
help_template = "\
\x1b[36;1mhaj load (alias: l)\x1b[0m
Usage: haj load [OPTIONS] <archive_path>
Description:
install a local package archive (.pkg.tar.zst) onto the system
Arguments:
<archive_path> the path to the local package archive file
Options:
-y, --noconfirm bypass all confirmation prompts
--root <PATH> specify an alternate installation root
-v, --verbose enable verbose debug logging
-d, --dry-run preview a command without modifying the system
-h, --help print help"
)]
Load { archive_path: String },
#[command(
aliases = ["f", "download", "get"],
help_template = "\
\x1b[36;1mhaj fetch (aliases: f, download, get)\x1b[0m
Usage: haj fetch [OPTIONS] <packages>...
Description:
download package archives to the cache directory without installing them
Arguments:
<packages>... list of packages to fetch
Options:
--root <PATH> specify an alternate installation root
-v, --verbose enable verbose debug logging
-d, --dry-run preview a command without modifying the system
-h, --help print help"
)]
Fetch { packages: Vec<String> },
#[command(
alias = "m",
help_template = "\
\x1b[36;1mhaj mark (alias: m)\x1b[0m
Usage: haj mark [OPTIONS] <package> [reason]
Description:
set or toggle an installed package's install reason
Examples:
haj mark bash
haj mark bash as explicit
haj mark bash dep
Arguments:
<package> the package to modify
[reason] optional reason: 'explicit'/'manual' or 'dep'/'deps'/'auto'
Options:
--as-explicit mark package as explicitly installed
--as-deps mark package as installed as a dependency
--root <PATH> specify an alternate installation root
-v, --verbose enable verbose debug logging
-d, --dry-run preview a command without modifying the system
-h, --help print help"
)]
Mark {
package: String,
reason: Option<String>,
#[arg(long)]
as_explicit: bool,
#[arg(long)]
as_deps: bool,
},
#[command(
aliases = ["pn", "pacnew", "merge"],
help_template = "\
\x1b[36;1mhaj diff (aliases: pn, pacnew, merge)\x1b[0m
Usage: haj diff [OPTIONS]
Description:
interactively search, manage, and merge .pacnew configuration files on the system
Options:
-d, --dry-run preview command without running pacdiff
-v, --verbose enable verbose debug logging
-h, --help print help"
)]
Diff,
#[command(
alias = "pb",
help_template = "\
\x1b[36;1mhaj pkgbuild (alias: pb)\x1b[0m
Usage: haj pkgbuild [OPTIONS] <package>
Description:
read and print the PKGBUILD file of a package from the AUR
Arguments:
<package> the package to fetch the PKGBUILD for
Options:
-d, --dry-run preview command without fetching
-h, --help print help"
)]
Pkgbuild { package: String },
#[command(hide = true)]
Completions {
#[arg(value_enum)]
shell: CompletionShell,
},
#[command(external_subcommand)]
Interactive(Vec<String>),
}
const KNOWN_VERBS: &[&str] = &[
"tui",
"t",
"install",
"add",
"i",
"a",
"remove",
"rm",
"toss",
"uninstall",
"delete",
"drop",
"update",
"up",
"sync",
"refresh",
"upgrade",
"jump",
"search",
"s",
"find",
"show",
"info",
"about",
"describe",
"group",
"g",
"list",
"ls",
"stats",
"st",
"history",
"h",
"downgrade",
"sink",
"rollback",
"clean",
"c",
"orphan",
"o",
"orphans",
"autoremove",
"prune",
"owns",
"ow",
"owner",
"which",
"locate",
"loc",
"where",
"find-file",
"files",
"lf",
"load",
"l",
"fetch",
"f",
"download",
"get",
"mark",
"m",
"diff",
"pn",
"pacnew",
"merge",
"pkgbuild",
"pb",
"completions",
"help",
];
fn takes_flag_value(arg: &str) -> bool {
if arg.contains('=') {
return false;
}
if matches!(
arg,
"-i" | "--ignore"
| "-c"
| "--config"
| "--root"
| "--from"
| "-l"
| "--limit"
| "-k"
| "--keep"
) {
return true;
}
!arg.starts_with("--")
&& arg.starts_with('-')
&& arg.len() > 2
&& matches!(arg.as_bytes().last(), Some(b'i' | b'c' | b'l' | b'k'))
}
pub fn normalize_args(raw: Vec<String>) -> Vec<String> {
if raw.len() <= 1 {
return raw;
}
let mut prefix_flags = Vec::new();
let mut rest = Vec::new();
let mut i = 1;
while i < raw.len() {
let arg = &raw[i];
if arg == "--" {
rest.extend_from_slice(&raw[i..]);
break;
}
if arg.starts_with('-') {
prefix_flags.push(arg.clone());
if takes_flag_value(arg) && i + 1 < raw.len() {
i += 1;
prefix_flags.push(raw[i].clone());
}
i += 1;
} else {
rest.extend_from_slice(&raw[i..]);
break;
}
}
if rest.is_empty() {
return raw;
}
if rest.len() >= 2 && rest[0] == "who" && rest[1] == "owns" {
rest.drain(0..2);
rest.insert(0, "owns".to_string());
} else if rest.len() >= 2 && rest[0] == "list" && rest[1] == "files" {
rest.drain(0..2);
rest.insert(0, "files".to_string());
}
let verb = rest[0].as_str();
if !KNOWN_VERBS.contains(&verb) {
return raw;
}
let mut tail = Vec::new();
let mut pos_idx = 0usize;
let mut j = 1;
while j < rest.len() {
let cur = &rest[j];
if cur == "--" {
tail.extend_from_slice(&rest[j..]);
break;
}
if cur.starts_with('-') {
tail.push(cur.clone());
if takes_flag_value(cur) && j + 1 < rest.len() {
j += 1;
tail.push(rest[j].clone());
}
j += 1;
continue;
}
if (cur == "from" || cur == "in")
&& j + 1 < rest.len()
&& matches!(
verb,
"install"
| "add"
| "i"
| "a"
| "search"
| "s"
| "find"
| "upgrade"
| "jump"
| "update"
| "up"
| "sync"
| "refresh"
| "show"
| "info"
| "about"
| "describe"
| "pkgbuild"
| "pb"
)
{
match rest[j + 1].as_str() {
"aur" => {
tail.push("--aur".to_string());
j += 2;
continue;
}
"repo" | "repos" => {
tail.push("--repo".to_string());
j += 2;
continue;
}
_ => {}
}
}
if matches!(verb, "downgrade" | "sink" | "rollback")
&& cur == "to"
&& pos_idx == 1
&& j + 1 < rest.len()
{
j += 1;
continue;
}
if matches!(verb, "mark" | "m") && cur == "as" && pos_idx == 1 && j + 1 < rest.len() {
j += 1;
continue;
}
if matches!(verb, "files" | "lf")
&& (cur == "in" || cur == "of")
&& pos_idx == 0
&& j + 1 < rest.len()
{
j += 1;
continue;
}
tail.push(cur.clone());
pos_idx += 1;
j += 1;
}
let mut out = Vec::with_capacity(1 + prefix_flags.len() + 1 + tail.len());
out.push(raw[0].clone());
out.extend(prefix_flags);
out.push(rest[0].clone());
out.extend(tail);
out
}
pub fn short_help_text() -> &'static str {
"\
the beautiful, cross-distro package manager and tui.
Usage: \x1b[36;1mhaj\x1b[0m [OPTIONS] <COMMAND>
Core: tui (t), sync (up), jump (upgrade), add (i), rm (toss), s (find),
show (info), ls (list), st (stats), h (history), o (orphan), c (clean)
More: group, load, fetch, downgrade (sink), owns, files, locate, mark,
diff, pkgbuild (pb)
Options:
-a, --aur restrict to aur/external sources
-r, --repo restrict to native repositories
-y, --noconfirm bypass confirmation prompts
-n, --needed skip up-to-date packages
-d, --dry-run preview without modifying the system
-V, --version show version info
-h, --help compact help ('--help' for full command list)
run 'haj --help', 'haj <cmd> --help', or 'man haj' for details."
}
pub fn is_short_help_request(args: &[String]) -> bool {
if args.len() < 2 || args.iter().any(|a| a == "--help") {
return false;
}
args[1..]
.iter()
.take_while(|a| a.starts_with('-'))
.any(|a| a == "-h")
}
pub fn parse_cli_from<I, S>(args: I) -> Result<Cli, clap::Error>
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
Cli::try_parse_from(normalize_args(args.into_iter().map(Into::into).collect()))
}
pub fn parse_cli() -> Result<Cli, clap::Error> {
let raw: Vec<String> = std::env::args_os()
.map(|s| s.to_string_lossy().into_owned())
.collect();
parse_cli_from(raw)
}
#[cfg(test)]
mod tests {
use super::*;
fn norm(args: &[&str]) -> Vec<String> {
normalize_args(args.iter().map(|s| s.to_string()).collect())
}
#[test]
fn test_normalize_natural_phrases() {
assert_eq!(
norm(&["haj", "add", "yay", "from", "aur"]),
vec!["haj", "add", "yay", "--aur"]
);
assert_eq!(
norm(&["haj", "search", "foo", "in", "repo"]),
vec!["haj", "search", "foo", "--repo"]
);
assert_eq!(
norm(&["haj", "downgrade", "bash", "to", "5.2"]),
vec!["haj", "downgrade", "bash", "5.2"]
);
assert_eq!(
norm(&["haj", "rollback", "--dry-run", "7zip", "to", "26.05"]),
vec!["haj", "rollback", "--dry-run", "7zip", "26.05"]
);
assert_eq!(
norm(&["haj", "mark", "bash", "as", "explicit"]),
vec!["haj", "mark", "bash", "explicit"]
);
assert_eq!(
norm(&["haj", "mark", "-d", "bash", "as", "dep"]),
vec!["haj", "mark", "-d", "bash", "dep"]
);
assert_eq!(
norm(&["haj", "who", "owns", "/usr/bin/bash"]),
vec!["haj", "owns", "/usr/bin/bash"]
);
assert_eq!(
norm(&["haj", "list", "files", "of", "bash"]),
vec!["haj", "files", "bash"]
);
assert_eq!(
norm(&["haj", "files", "-v", "in", "bash"]),
vec!["haj", "files", "-v", "bash"]
);
assert_eq!(
norm(&["haj", "-vc", "pacman.conf", "install", "fd", "from", "repo"]),
vec!["haj", "-vc", "pacman.conf", "install", "fd", "--repo"]
);
assert_eq!(
norm(&["haj", "install", "--", "from", "aur"]),
vec!["haj", "install", "--", "from", "aur"]
);
}
#[test]
fn test_bare_interactive_query_untouched() {
assert_eq!(
norm(&["haj", "text", "to", "speech"]),
vec!["haj", "text", "to", "speech"]
);
}
fn strip_ansi(s: &str) -> String {
let mut out = String::with_capacity(s.len());
let mut chars = s.chars();
while let Some(c) = chars.next() {
if c == '\x1b' {
for n in chars.by_ref() {
if n == 'm' {
break;
}
}
} else {
out.push(c);
}
}
out
}
#[test]
fn test_help_outputs_fit_80_columns() {
for line in strip_ansi(short_help_text()).lines() {
assert!(line.len() <= 80, "short -h line too wide: {line}");
}
assert!(short_help_text().lines().count() <= 20);
use clap::CommandFactory;
let long_help = Cli::command().render_long_help().to_string();
for line in strip_ansi(&long_help).lines() {
assert!(line.len() <= 80, "--help line exceeds 80 cols: {line}");
}
assert!(is_short_help_request(&["haj".into(), "-h".into()]));
assert!(!is_short_help_request(&["haj".into(), "--help".into()]));
assert!(!is_short_help_request(&[
"haj".into(),
"install".into(),
"-h".into()
]));
}
#[test]
fn test_completion_shell_enum_parsing() {
assert!(matches!(
Cli::try_parse_from(["haj", "completions", "bash"])
.unwrap()
.command,
Some(Commands::Completions {
shell: CompletionShell::Bash
})
));
assert!(matches!(
Cli::try_parse_from(["haj", "completions", "zsh"])
.unwrap()
.command,
Some(Commands::Completions {
shell: CompletionShell::Zsh
})
));
assert!(matches!(
Cli::try_parse_from(["haj", "completions", "fish"])
.unwrap()
.command,
Some(Commands::Completions {
shell: CompletionShell::Fish
})
));
assert!(Cli::try_parse_from(["haj", "completions", "powershell"]).is_err());
}
}