fix completion

This commit is contained in:
steven-omaha
2023-02-24 14:33:51 +01:00
parent e4fe73c7eb
commit 5e82ace871
3 changed files with 45 additions and 28 deletions
+39 -26
View File
@@ -13,37 +13,50 @@ _pacdef() {
function _subcommands { function _subcommands {
local -a subcommands local -a subcommands
subcommands=( subcommands=(
'group:manage groups (alias: g)' 'group:manage groups'
'package:manage packages (alias: p)' 'g:manage groups'
'version:show version info (alias: v)' 'package:manage packages'
'p:manage packages'
'version:show version'
) )
_describe 'subcommand' subcommands _describe 'pacdef subcommand' subcommands
} }
function _group_actions { function _group_actions {
local -a group_actions local -a group_actions
group_actions=( group_actions=(
'edit:edit an imported group file (alias: e)' 'e:edit an imported group file'
'list:show names of imported groups (alias: l)' 'edit:edit an imported group file'
'import:import a new group file (alias: i)' 'l:show names of imported groups'
'new:create a new group file (alias: n)' 'list:show names of imported groups'
'remove:remove a group file (alias: r)' 'i:import a new group file'
'show:show packages under an imported group (alias: s)' '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 { function _package_actions {
local -a package_actions local -a package_actions
package_actions=( package_actions=(
'clean:uninstall packages not managed by pacdef (alias: c)' 'c:uninstall packages not managed by pacdef'
'review:review unmanaged packages (alias: r)' 'clean:uninstall packages not managed by pacdef'
'search:show the group containing a package (alias: se)' 'r:review unmanaged packages'
'sync:install all packages from imported groups (alias: sy)' 'review:review unmanaged packages'
'unmanaged:show explicitly installed packages not managed by pacdef (alias: u)' '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 \ _arguments -C \
@@ -54,13 +67,13 @@ _pacdef() {
case $state in case $state in
(args) (args)
case $line[1] in case $line[1] in
package) (p|package)
case $line[2] in case $line[2] in
search) (se|search)
_arguments \ _arguments \
"2:regex:" && ret=0 "2:regex:" && ret=0
;; ;;
(clean|review|sync|unmanaged|help) (c|clean|r|review|sy|sync|u|unmanaged)
_message "no more arguments" && ret=0 _message "no more arguments" && ret=0
;; ;;
*) *)
@@ -70,19 +83,19 @@ _pacdef() {
;; ;;
esac esac
;; ;;
group) (g|group)
case $line[2] in case $line[2] in
list) (l|list)
_message "no more arguments" && ret=0 _message "no more arguments" && ret=0
;; ;;
(edit|remove|show) (e|edit|r|remove|s|show)
_arguments "*:group file:_files -W '$GROUPDIR'" && ret=0 _arguments "*:group file(s):_files -W '$GROUPDIR'" && ret=0
;; ;;
import) (i|import)
_arguments "*:new group file(s):_files" && ret=0 _arguments "*:new group file(s):_files" && ret=0
;; ;;
new) (n|new)
_arguments \ _arguments \
{-e,--edit}"[edit group file after creating them]" \ {-e,--edit}"[edit group file after creating them]" \
"*:new group name(s):" \ "*:new group name(s):" \
+5 -1
View File
@@ -91,7 +91,11 @@ fn get_package_cmd() -> Command {
.visible_alias("se") .visible_alias("se")
.about("search for packages which match a provided string literal or regex") .about("search for packages which match a provided string literal or regex")
.arg_required_else_help(true) .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") Command::new("package")
.arg_required_else_help(true) .arg_required_else_help(true)
+1 -1
View File
@@ -10,7 +10,7 @@ use crate::grouping::{Group, Package, Section};
pub fn search_packages(args: &ArgMatches, groups: &HashSet<Group>) -> Result<()> { pub fn search_packages(args: &ArgMatches, groups: &HashSet<Group>) -> Result<()> {
let search_string = args let search_string = args
.get_one::<String>("string") .get_one::<String>("regex")
.context("getting search string from arg")?; .context("getting search string from arg")?;
let re = Regex::new(search_string)?; let re = Regex::new(search_string)?;