From 5e82ace871ff460d8f0eb13c8396069fe7a511e9 Mon Sep 17 00:00:00 2001 From: steven-omaha <35634100+steven-omaha@users.noreply.github.com> Date: Fri, 24 Feb 2023 14:33:51 +0100 Subject: [PATCH] fix completion --- _completion.zsh | 65 +++++++++++++++++++------------- crates/pacdef_core/src/args.rs | 6 ++- crates/pacdef_core/src/search.rs | 2 +- 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/_completion.zsh b/_completion.zsh index a9beae9..5204f38 100644 --- a/_completion.zsh +++ b/_completion.zsh @@ -13,37 +13,50 @@ _pacdef() { function _subcommands { local -a subcommands subcommands=( - 'group:manage groups (alias: g)' - 'package:manage packages (alias: p)' - 'version:show version info (alias: v)' + 'group:manage groups' + 'g:manage groups' + 'package:manage packages' + 'p:manage packages' + 'version:show version' ) - _describe 'subcommand' subcommands + _describe 'pacdef subcommand' subcommands } function _group_actions { local -a group_actions group_actions=( - 'edit:edit an imported group file (alias: e)' - 'list:show names of imported groups (alias: l)' - 'import:import a new group file (alias: i)' - 'new:create a new group file (alias: n)' - 'remove:remove a group file (alias: r)' - 'show:show packages under an imported group (alias: s)' + 'e:edit an imported group file' + 'edit:edit an imported group file' + 'l:show names of imported groups' + 'list:show names of imported groups' + 'i:import a new group file' + 'import:import a new group file' + 'n:create a new group file' + 'new:create a new group file' + 'r:remove a group file' + 'remove:remove a group file' + 's:show packages under an imported group' + 'show:show packages under an imported group' ) - _describe 'group action' group_actions + _describe 'pacdef group action' group_actions } function _package_actions { local -a package_actions package_actions=( - 'clean:uninstall packages not managed by pacdef (alias: c)' - 'review:review unmanaged packages (alias: r)' - 'search:show the group containing a package (alias: se)' - 'sync:install all packages from imported groups (alias: sy)' - 'unmanaged:show explicitly installed packages not managed by pacdef (alias: u)' + 'c:uninstall packages not managed by pacdef' + 'clean:uninstall packages not managed by pacdef' + 'r:review unmanaged packages' + 'review:review unmanaged packages' + 'se:show the group containing a package' + 'search:show the group containing a package' + 'sy:install all packages from imported groups' + 'sync:install all packages from imported groups' + 'u:show explicitly installed packages not managed by pacdef' + 'unmanaged:show explicitly installed packages not managed by pacdef' ) - _describe 'package action' package_actions + _describe 'pacdef package action' package_actions } _arguments -C \ @@ -54,13 +67,13 @@ _pacdef() { case $state in (args) case $line[1] in - package) + (p|package) case $line[2] in - search) + (se|search) _arguments \ "2:regex:" && ret=0 ;; - (clean|review|sync|unmanaged|help) + (c|clean|r|review|sy|sync|u|unmanaged) _message "no more arguments" && ret=0 ;; *) @@ -70,19 +83,19 @@ _pacdef() { ;; esac ;; - group) + (g|group) case $line[2] in - list) + (l|list) _message "no more arguments" && ret=0 ;; - (edit|remove|show) - _arguments "*:group file:_files -W '$GROUPDIR'" && ret=0 + (e|edit|r|remove|s|show) + _arguments "*:group file(s):_files -W '$GROUPDIR'" && ret=0 ;; - import) + (i|import) _arguments "*:new group file(s):_files" && ret=0 ;; - new) + (n|new) _arguments \ {-e,--edit}"[edit group file after creating them]" \ "*:new group name(s):" \ diff --git a/crates/pacdef_core/src/args.rs b/crates/pacdef_core/src/args.rs index 75a2bc8..8db684e 100644 --- a/crates/pacdef_core/src/args.rs +++ b/crates/pacdef_core/src/args.rs @@ -91,7 +91,11 @@ fn get_package_cmd() -> Command { .visible_alias("se") .about("search for packages which match a provided string literal or regex") .arg_required_else_help(true) - .arg(Arg::new("string").required(true)); + .arg( + Arg::new("regex") + .required(true) + .help("the regular expression the package must match"), + ); Command::new("package") .arg_required_else_help(true) diff --git a/crates/pacdef_core/src/search.rs b/crates/pacdef_core/src/search.rs index 9393d20..3fb0a89 100644 --- a/crates/pacdef_core/src/search.rs +++ b/crates/pacdef_core/src/search.rs @@ -10,7 +10,7 @@ use crate::grouping::{Group, Package, Section}; pub fn search_packages(args: &ArgMatches, groups: &HashSet) -> Result<()> { let search_string = args - .get_one::("string") + .get_one::("regex") .context("getting search string from arg")?; let re = Regex::new(search_string)?;