zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: complete Debian architectures in common function
@ 2014-10-10 23:17 Oliver Kiddle
  2014-10-11  0:27 ` Axel Beckert
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Kiddle @ 2014-10-10 23:17 UTC (permalink / raw)
  To: Zsh workers

Quite a few of the Debian completions need to complete the Debian
architectures. This factors that out into _deb_architectures. You can
pass it extra values such as with -a "source all" if those are possible
matches. I've also updated or fixed other areas of affected functions,
particularly _apt-file.

Oliver

diff --git a/Completion/Debian/Command/_apt-file b/Completion/Debian/Command/_apt-file
index eddbbdc..98a93fd 100644
--- a/Completion/Debian/Command/_apt-file
+++ b/Completion/Debian/Command/_apt-file
@@ -1,55 +1,59 @@
 #compdef apt-file
 
-_apt-file() {
-  local -a arguments
-  local state line cmds 
-  arguments=(
-    '(--cache -c)'{--cache,-c}'[cache directory]:directory:_directories'
-    '(-v --verbose)'{-v,--verbose}'[verbose]'
-     '(--cdrom-mount -d)'{--cdrom-mount,-d}'[cdrom mount point]:directory:_directories'
-     '(--ignore-case -i)'{--ignore-case,-i}'[ignore case]'
-     '(--regexp -r)'{--regexp,-r}'[regular expression]'
-     '(-V --version)'{-V,--version}'[version]'
-     '(-a --architecture)'{-a,--architecture}'[architecture]:architecture:(alpha arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)'
-    '(-s --sources-list)'{-s,--sources-list}'[source.list file]:file:_files'
-    '(-l --package-only)'{-l,--package-only}'[only display package name]'
-    '(-F --fixed-string)'{-F,--fixed-string}'[do not expand search pattern]'
-    '(-y --dummy)'{-y,--dummy}'[run in dummy mode]'
-    '(-h --help)'{-h,--help}'[display help screen]'
-    '1: :->cmds'
-    '*: :->args'
-  )
-    _arguments -S $arguments
+local curcontext="$curcontext" state line expl cmds ret=1
+typeset -A opt_args
 
-    case $state in
-      cmds)
-        cmds=(
-            'update:resynchronize package contents'
-            'search:search in which package file is included'
-            'list:list contents of a package'
-            'show:alias for list'
-            'purge:remove all Contents-<ARCH>.gz files in cache directory'
-        )
-        _describe -t commands 'apt-list command' cmds && ret=0
+_arguments -C -S \
+  '(--cache -c)'{--cache,-c}'[cache directory]:directory:_directories' \
+  '(-v --verbose)'{-v,--verbose}'[verbose]' \
+  '(--cdrom-mount -d)'{--cdrom-mount,-d}'[cdrom mount point]:directory:_directories' \
+  '(--from-file -f --from-deb -D)'{--from-file,-f}'[read patterns from given file]' \
+  '(--from-deb -D --from-file -f)'{--from-dev,-D}'[use contents of given .deb archives as patterns]' \
+  '(--ignore-case -i)'{--ignore-case,-i}'[ignore case]' \
+  '(--regexp -x)'{--regexp,-x}'[regular expression]' \
+  '(-V --version)'{-V,--version}'[version]' \
+  '(-a --architecture)'{-a,--architecture}'[architecture]:architecture:_deb_architectures' \
+  '(-s --sources-list)'{-s,--sources-list}'[source.list file]:file:_files' \
+  '(-l --package-only)'{-l,--package-only}'[only display package name]' \
+  '(-N --non-interactive)'{-N,--non-interactive}'[skip schemes requiring user input]' \
+  '(-F --fixed-string)'{-F,--fixed-string}'[do not expand search pattern]' \
+  '(-y --dummy)'{-y,--dummy}'[run in dummy mode]' \
+  '(-)'{-h,--help}'[display help screen]' \
+  '1: :->cmds' \
+  '*: :->args' && ret=0
+
+case $state in
+  cmds)
+    cmds=(
+      'update:resynchronize package contents'
+      {find,search}:'search in which package file is included'
+      {list,show}:'list contents of a package'
+      'purge:remove all Contents-<ARCH>.gz files in cache directory'
+    )
+    _describe -t commands 'apt-list command' cmds
+  ;;
+  args)
+    case $line[1] in
+      search|find)
+	if (( $#opt_args[(I)(-D|--from-deb)] )); then
+	  _wanted files expl 'debian package' _files -g '*.deb(-.)'
+	elif (( $#opt_args[(I)(-f|--from-file)] )); then
+          _files
+	else
+	  _message -e patterns "pattern"
+	fi
+      ;;
+      list|show)
+	_deb_packages avail
       ;;
-      args)
-        case $line[1] in
-            search)
-                _message "pattern"
-            ;;
-            list|show)
-               _deb_packages avail 
-            ;;
-            update|purge)
-                # do nothing
-            ;;
-            *)
-                _message "command $line[1] not available"
-            ;;
-        esac
+      update|purge)
+	# do nothing
+      ;;
+      *)
+	_message "command $line[1] not available"
       ;;
     esac
+  ;;
+esac && ret=0
 
-}
-
-_apt-file "$@"
+return ret
diff --git a/Completion/Debian/Command/_dak b/Completion/Debian/Command/_dak
index 840fc00..086196c 100644
--- a/Completion/Debian/Command/_dak
+++ b/Completion/Debian/Command/_dak
@@ -1,31 +1,26 @@
 #compdef dak
 
-local curcontext="$curcontext" state line expl cmd args ret=1
-typeset -A opt_args
+local expl cmd args ret=1
 
-_arguments -C \
-    '1: :->cmd' \
-    '*:: :->args' && ret=0
-
-if (( ! $+_dak_cmds )); then
+if (( CURRENT == 2 )); then
+  if (( ! $+_dak_cmds )); then
     typeset -gH _dak_cmds
     _dak_cmds=(${${${(f)${"$(_call_program dak dak --help)"#*Availa#ble commands:}}#[^a-z] ##}%%[ 	]*})
-fi
+  fi
 
-if [[ $state != 'args' ]]; then
-    _describe -t subcommand 'subcommand' _dak_cmds
-    return 0
+  _describe -t subcommands 'subcommand' _dak_cmds
+  return
 fi
 
-cmd="$words[1]"
-curcontext="${curcontext%:*:*}:dak-$cmd:"
+cmd="$words[2]"
+local curcontext="${curcontext%:*:*}:dak-$cmd:"
 
 args=( '(-)'{--help,-h}'[show help message]' )
 
 case $cmd in
 (ls)
     args+=(
-  '(-a --architecture)'{-a,--architecture=}':arch:_values -s , "architecture list" source all alpha amd64 arm hppa hurd-i386 i386 ia64 mips mipsel'
+  '(-a --architecture)'{-a,--architecture=}':arch:_sequence _deb_architectures -a "all source"'
   '(-b --binary-type)'{-b,--binary-type=}':type:(deb udeb)'
   '(-c --component)'{-c,--component=}':component:_values -s , "component list" main contrib non-free'
   '(-g --greaterorequal)'{-g,--greaterorequal}
@@ -70,7 +65,7 @@ case $cmd in
     ;;
 (rm)
     args+=(
-  '(-a --architecture)'{-a,--architecture=}':arch:_values -s , "architecture list" source all alpha amd64 arm hppa hurd-i386 i386 ia64 mips mipsel'
+  '(-a --architecture)'{-a,--architecture=}':arch:_sequence _deb_architectures -a "all source"'
   '(-b --binary)'{-b,--binary}'[remove binaries only]'
   '(-c --component)'{-c,--component=}':component:_values -s , "component list" main contrib non-free'
   '(-C --carbon-copy)'{-C,--carbon-copy=}':cc address:_email_addresses'
@@ -96,7 +91,7 @@ case $cmd in
 
 (make-suite-file-list)
     args+=(
-   '(-a --architecture)'{-a,--architecture=}':arch:_values -s , "architecture list" source all alpha amd64 arm hppa hurd-i386 i386 ia64 mips mipsel'
+   '(-a --architecture)'{-a,--architecture=}':arch:_sequence _deb_architectures -a "all source"'
   '(-c --component)'{-c,--component=}':component:_values -s , "component list" main contrib non-free'
   '(-n --no-delete)'{-n,--no-delete}'[do not delete older versions]'
   '(-s --suite)'{-s,--suite=}':suite:_values -s , "suite list" oldstable stable testing unstable experimental'
@@ -239,10 +234,10 @@ case $cmd in
     ;;
 
     (*)
-    _files
+      args+=( '*: :_default' )
     ;;
 
 esac
 
 _arguments -s "$args[@]" && ret=0
-return $ret
+return ret
diff --git a/Completion/Debian/Command/_dpkg-buildpackage b/Completion/Debian/Command/_dpkg-buildpackage
index d6f5c5f..b0eea57 100644
--- a/Completion/Debian/Command/_dpkg-buildpackage
+++ b/Completion/Debian/Command/_dpkg-buildpackage
@@ -5,7 +5,7 @@ _arguments \
   '-B[binary-only build, no source or arch-indep binaries]' \
   '-S[source-only build, no binaries]' \
   '-s-:source generation:((i\:default a\:force\ inclusion\ of\ original\ source d\:force\ exclusion\ of\ original\ source))' \
-  '-a-:architecture:(alpha amd64 arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)' \
+  '-a-:architecture:_deb_architectures' \
   '-v-:version:' \
   '-C-:changes description:_files' \
   '-m-:maintainer address:_email_addresses' \
diff --git a/Completion/Debian/Command/_dpkg-repack b/Completion/Debian/Command/_dpkg-repack
index 5d625a5..37f8005 100644
--- a/Completion/Debian/Command/_dpkg-repack
+++ b/Completion/Debian/Command/_dpkg-repack
@@ -2,6 +2,6 @@
 
 _arguments \
   '--root=[take package from filesystem rooted on <dir>]:root dir:_files -/' \
-  '--arch=[force the package to be built for architecture <arch>]:architecture:(alpha amd64 arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)' \
+  '--arch=[force the package to be built for specified architecture]:architecture:_deb_architectures' \
   '--generate[generate build directory but do not build deb]' \
   '*:package:_deb_packages xinstalled'
diff --git a/Completion/Debian/Command/_lintian b/Completion/Debian/Command/_lintian
index 554be45..773e7a1 100644
--- a/Completion/Debian/Command/_lintian
+++ b/Completion/Debian/Command/_lintian
@@ -31,7 +31,7 @@ case "$service" in
       '--archivedir:archive directory:_files -/' \
       '--dist:distribution:(woody sarge sid)' \
       '--section:release:(main contrib non-free)' \
-      '--arch:architecture:(alpha arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)' \
+      '--arch:architecture:_deb_architectures' \
       '--root:root directory:_files -/' \
       '(-a --all)'{-a,--all}'[check all packages in the distribution]' \
       '(-b --binary)'{-b,--binary}'[the following packages are binary]' \
diff --git a/Completion/Debian/Command/_madison b/Completion/Debian/Command/_madison
index fc4821e..445b79a 100644
--- a/Completion/Debian/Command/_madison
+++ b/Completion/Debian/Command/_madison
@@ -1,7 +1,7 @@
 #compdef madison rmadison
 
 _arguments \
-  '(-a --architecture)'{-a,--architecture=}':arch:_values -s , "architecture list" source all alpha arm hppa hurd-i386 i386 ia64 mips mipsel' \
+  '(-a --architecture)'{-a,--architecture=}':arch:_sequence _deb_architectures -a "all source" -' \
   '(-b --binary)'{-b,--binary-type=}':type:(deb udeb)' \
   '(-c --component)'{-c,--component=}':component:_values -s , "component list" main contrib non-free' \
   '(-g --greaterorequal)'{-g,--greaterorequal} \
diff --git a/Completion/Debian/Command/_pbuilder b/Completion/Debian/Command/_pbuilder
index 7811d56..9322d03 100644
--- a/Completion/Debian/Command/_pbuilder
+++ b/Completion/Debian/Command/_pbuilder
@@ -14,8 +14,8 @@ else
     '--buildresult:location:_files -/' \
     '--mirror:URL:_urls' \
     '--othermirror:URL:_urls' \
-    '--distribution:suite:(breezy dapper edgy etch feisty gutsy hardy hoary intrepid jaunty karmic lenny lucid potato sarge sid squeeze warty woody' \
-    '--architecture:architecture:(alpha amd64 armel hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)' \
+    '--distribution:suite:(breezy dapper edgy etch feisty gutsy hardy hoary intrepid jaunty jessie karmic lenny lucid potato sarge sid squeeze warty woody' \
+    '--architecture:architecture:i_deb_architectures' \
     '--components:component:(main contrib non-free)' \
     '--override-config' \
     '--hookdir:location:_files -/' \
diff --git a/Completion/Debian/Command/_reprepro b/Completion/Debian/Command/_reprepro
index 44ed154..d1e124e 100644
--- a/Completion/Debian/Command/_reprepro
+++ b/Completion/Debian/Command/_reprepro
@@ -1,10 +1,10 @@
 #compdef reprepro
 
-local context state line distfile
+local curcontext="$curcontext" state line expl distfile ret=1
 typeset -A opt_args
 local -a codenames
 
-_arguments \
+_arguments -C \
   '(-h --help)'{-h,--help}'[display help]' \
   '*'{-v,-V,--verbose}'[be more verbose]' \
   '--silent[be less verbose]' \
@@ -17,7 +17,7 @@ _arguments \
   '--listdir:list dir:_files -/' \
   '--methoddir:method dir:_files -/' \
   '(-C --component)'{-C,--component}':component:(component1 component2)' \
-  '(-A --architecture)'{-A,--architecture}':architecture:(amd64 sparc)' \
+  '(-A --architecture)'{-A,--architecture}':architecture:_sequence -s "|" _deb_architectures -' \
   '(-T --type)'{-T,--type}':file type:(dsc deb udeb)' \
   '(-S --section)'{-S,--section}':section:(section1 section2)' \
   '(-P --priority)'{-P,--priority}':priority:(high low)' \
@@ -40,12 +40,11 @@ _arguments \
     rereference dumpreferences dumpunreferenced deleteunreferenced
     reoverride dumptracks retrack removealltracks removetrack tidytracks
     copy clearvanished gensnapshot rerunnotifiers)' \
-  '*::subcmd:->subcmd' && return 0
+  '*::subcmd:->subcmd' && ret=0
 
 case "$state" in
-    (subcmd)
-
-  case "$words[1]" in
+  subcmd)
+    case "$words[1]" in
       (export|update|iteratedupdate|checkupdate|predelete|pull|checkpull|check)
         if [[ -n "$opt_args[--confdir]" ]]; then
 	  distfile=${opt_args[--confdir]}/distributions
@@ -60,11 +59,13 @@ case "$state" in
 	fi
 
         codenames=($(awk '/^[Cc][Oo][Dd][Ee][Nn][Aa][Mm][Ee]: / {$1="";print}' "$distfile"))
-      	_wanted -V 'codenames' expl 'codename' compadd -a codenames
-	;;
+	_wanted -V 'codenames' expl 'codename' compadd -a codenames && ret=0
+      ;;
       (*)
-    	_files
-    	;;
-  esac
+	_files && ret=0
+      ;;
+    esac
   ;;
 esac
+
+return ret
diff --git a/Completion/Debian/Command/_svn-buildpackage b/Completion/Debian/Command/_svn-buildpackage
index 0b4d501..e0f9258 100644
--- a/Completion/Debian/Command/_svn-buildpackage
+++ b/Completion/Debian/Command/_svn-buildpackage
@@ -28,8 +28,8 @@ _arguments \
   '-B[binary-only build, no source or arch-indep binaries]' \
   '-S[source-only build, no binaries]' \
   '-s-:source generation:((i\:default a\:force\ inclusion\ of\ original\ source d\:force\ exclusion\ of\ original\ source))' \
-  '-a-:architecture:(alpha amd64 arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)' \
-  '-v-:version:' \
+  '-a-:architecture:_deb_architectures' \
+  '-v-:version' \
   '-C-:changes description:_files' \
   '-m-:maintainer address:_email_addresses' \
   '-e-:maintainer address:_email_addresses' \
diff --git a/Completion/Debian/Type/_deb_architectures b/Completion/Debian/Type/_deb_architectures
new file mode 100644
index 0000000..79f2c6a
--- /dev/null
+++ b/Completion/Debian/Type/_deb_architectures
@@ -0,0 +1,9 @@
+#autoload
+
+local extra
+zparseopts -E -D -a extra a:
+
+_description architectures expl 'architecture'
+compadd "$@" "$expl[@]" alpha amd64 arm64 armel armhf hppa hurd-i386 i386 ia64 \
+    kfreebsd-amd64 kfreebsd-i386 m68k mips mipsel powerpc powerpcspe ppc64 \
+    ppc64el s390x sh4 sparc sparc64 x32 ${=extra[2]}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: complete Debian architectures in common function
  2014-10-10 23:17 PATCH: complete Debian architectures in common function Oliver Kiddle
@ 2014-10-11  0:27 ` Axel Beckert
  0 siblings, 0 replies; 2+ messages in thread
From: Axel Beckert @ 2014-10-11  0:27 UTC (permalink / raw)
  To: zsh-workers

Hi Oliver,

On Sat, Oct 11, 2014 at 01:17:44AM +0200, Oliver Kiddle wrote:
> Quite a few of the Debian completions need to complete the Debian
> architectures. This factors that out into _deb_architectures.

Indeed. Thanks!

A few thoughts:

> +_description architectures expl 'architecture'
> +compadd "$@" "$expl[@]" alpha amd64 arm64 armel armhf hppa hurd-i386 i386 ia64 \
> +    kfreebsd-amd64 kfreebsd-i386 m68k mips mipsel powerpc powerpcspe ppc64 \
> +    ppc64el s390x sh4 sparc sparc64 x32 ${=extra[2]}

I wonder how much sense it may make to use the output of
"dpkg-architecture -L" as values.

While it would make the list always being uptodate, it would not work
on systems where dpkg-dev is not installed, especially not on
non-debianoid systems. And the list contains way more fictional (i.e.
potential future) architectures (> 400) than really existing
architectures.

OTOH I don't miss much in the above list and a hardcoded list is
surely faster than depending on some command's output.

>From a first glance the no more supported s390 and lpia (the latter
was Ubuntu-only) and the never taken off avr32 are missing, but then
again omitting no more existing architectures may be on purpose.

A potential compromise would be using "dpkg-architecture -L | fgrep -v
-- -" plus the three non-linux architectures listed above.

The output of the command (without the three non-linux architectures
added) gives us:

alpha
amd64
arm
arm64
armeb
armel
armhf
avr32
hppa
i386
ia64
m32r
m68k
mips
mips64
mips64el
mipsel
mipsn32
mipsn32el
or1k
powerpc
powerpcel
powerpcspe
ppc64
ppc64el
s390
s390x
sh3
sh3eb
sh4
sh4eb
sparc
sparc64
x32

Then again even the full list doesn't include the architecture
"illumos-amd64" as used on http://apt.osdyson.org/dists/lacaille/main/.
(Dyson is a project which tries port Debian onto the Illumos kernel.
The project even maintains a derivative of Debian's zsh package at
http://cgit.osdyson.org/zsh.git/! :-)

So maybe we should just merge the list above into the hardcoded one by
Oliver, maybe omitting some no more existing architectures and adding
illumos-amd64.

		Kind regards, Axel
-- 
/~\  Plain Text Ribbon Campaign                   | Axel Beckert
\ /  Say No to HTML in E-Mail and News            | abe@deuxchevaux.org  (Mail)
 X   See http://www.nonhtmlmail.org/campaign.html | abe@noone.org (Mail+Jabber)
/ \  I love long mails: http://email.is-not-s.ms/ | http://noone.org/abe/ (Web)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-10-11  0:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-10 23:17 PATCH: complete Debian architectures in common function Oliver Kiddle
2014-10-11  0:27 ` Axel Beckert

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).