diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2009-06-20 00:14:09 +0200 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2009-06-20 00:14:09 +0200 |
commit | 7d45ad0788a8ee72fc137b4722f223f673c693af (patch) | |
tree | 957edd6f72131945d493f7281e013a4bb5fbf604 | |
parent | 90234c148e98ce9f7d26b37218a5f2db4c8b5858 (diff) |
apt-why: Simplified --deptype parsing
-rwxr-xr-x | bin/apt-why | 10 | ||||
-rw-r--r-- | provides/zsh/completions/_apt-why | 14 |
2 files changed, 15 insertions, 9 deletions
diff --git a/bin/apt-why b/bin/apt-why index f5c2093..893fd6f 100755 --- a/bin/apt-why +++ b/bin/apt-why @@ -11,22 +11,16 @@ use Getopt::Long; my $cache = AptPkg::Cache->new; my $max_depth = 5; my $all = 0; -my @deptypes; -my @default_deptypes = ('Depends', 'Recommends', 'Suggests'); +my @deptypes = ('Depends', 'Recommends', 'Suggests'); GetOptions( 'all!' => \$all, - 'deptype=s' => \@deptypes, + 'deptype=s' => sub {shift; @deptypes = split(/,/, shift)}, 'depth=i' => \$max_depth, 'h|?|help' => \&usage, ); my $packagename = shift or die("No packagename given"); my @known; -@deptypes = split(/,/, join(',', @deptypes)); -unless (@deptypes) { - @deptypes = @default_deptypes; -} - sub usage { exec('perldoc', '-F', $0) or die("See perldoc -F $0"); } diff --git a/provides/zsh/completions/_apt-why b/provides/zsh/completions/_apt-why index a014c45..20c39bb 100644 --- a/provides/zsh/completions/_apt-why +++ b/provides/zsh/completions/_apt-why @@ -6,10 +6,22 @@ typeset -a arguments +function _apt-why_deptype { + typeset prefix='' + typeset -a keys used_prefixes + keys=(Depends Recommends Suggests) + if [[ -prefix *, ]] { + prefix=${words[$CURRENT]%,*}, + used_prefixes=(${(s:,:)prefix}) + } + _wanted expression expl 'dependency type' \ + compadd -F used_prefixes -qS , -P "$prefix" $keys +} + arguments=( '--all[consider all available packages]' '--depth=-[recursion depth]:recursion depth' - '*--deptype=-[filter by dependency type]:dependency type:(Depends Recommends Suggests)' + '--deptype[filter by dependency type]:dependency type:_apt-why_deptype' '*:package:_deb_packages "" avail' ) |