zsh-workers
 help / color / mirror / code / Atom feed
* Completion of swift fails when swift(1) is from Apple, not OpenStack
@ 2017-01-28 17:34 Zhiming Wang
  2017-01-28 17:42 ` Zhiming Wang
  2017-01-28 18:08 ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: Zhiming Wang @ 2017-01-28 17:34 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 2961 bytes --]

I was giving Apple's Swift programming language a try just now, and was
surprised to find out zshcompsys doesn't play nicely at all with swift(1) -- it
fails with an error.

Reproducer: with no swift(1) installed or swift(1) from Apple:

   $ autoload -Uz compinit; compinit
   $ swift <TAB>
   _values:compvalues:10: not enough arguments
   $ swift

and using _complete_debug (here[1] is the full log) I easily located the
culprit, _openstack, which was added in commit 89e319f34 and binds as many as
23 commands, including swift. 89e319f34 was first shipped in Zsh 5.3 in
December 2016. It makes assumptions about what swift --help should print, and
fails ungracefully when its expectations are off.

Now that the conflict is obvious, I wonder what's the best course of
action. For the reference, Swift is growing in popularity very rapidly; it
ranked #14 in 2016 on GitHub's list of most popular languages.[2] I don't know
how popular OpenStack is, let alone one of the 23 commands of its command-line
client, but I doubt it can beat *the* language of Apple platforms going
forward. Zsh 5.3 hasn't been out for very long, and Swift developers probably
haven't picked it up, since the latest version of macOS, 10.12.3, bundles Zsh
5.2. I'm afraid many people, who may not know how to program Zsh's compsys,
will be in for a big surprise when Apple bundles Zsh 5.3+ in the next major
macOS release.

Therefore, I suggest unbinding swift from _openstack. OpenStack folks can
always bind it back with compdef _openstack swift.

[1] https://gist.github.com/5a08aec1a4184325e0f2b52931473f92
[2] https://octoverse.github.com/


From 6563808d7bec41f66cf7e3b181e75ed19d32f2ac Mon Sep 17 00:00:00 2001
From: Zhiming Wang <zmwangx@gmail.com>
Date: Fri, 27 Jan 2017 22:23:35 -0500
Subject: [PATCH] _openstack: unbind swift

The name swift conflicts with the Swift compiler, the programming language for
Apple platforms (swift.org), which is arguably much more popular.

OpenStack folks who need completion for their swift could always bind it back:

   compdef _openstack swift
---
Completion/Unix/Command/_openstack | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_openstack b/Completion/Unix/Command/_openstack
index 39fa30c3a..69e492156 100644
--- a/Completion/Unix/Command/_openstack
+++ b/Completion/Unix/Command/_openstack
@@ -1,4 +1,4 @@
-#compdef openstack aodh barbican ceilometer cinder cloudkitty designate glance gnocchi heat ironic keystone magnum manila mistral monasca murano neutron nova sahara senlin swift trove
+#compdef openstack aodh barbican ceilometer cinder cloudkitty designate glance gnocchi heat ironic keystone magnum manila mistral monasca murano neutron nova sahara senlin trove

# https://wiki.openstack.org/wiki/OpenStackClients
# http://docs.openstack.org/user-guide/common/cli-install-openstack-command-line-clients.html
--
2.11.0

[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: Completion of swift fails when swift(1) is from Apple, not OpenStack
  2017-01-28 17:34 Completion of swift fails when swift(1) is from Apple, not OpenStack Zhiming Wang
@ 2017-01-28 17:42 ` Zhiming Wang
  2017-01-28 18:08 ` Bart Schaefer
  1 sibling, 0 replies; 6+ messages in thread
From: Zhiming Wang @ 2017-01-28 17:42 UTC (permalink / raw)
  To: Zhiming Wang; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 420 bytes --]

By the way, it seems that my main email address, zmwangx AT gmail.com, is now
blocked by the mailing list (I sent the exact same message with that address
yesterday, and it never showed up in the archive), despite successfully posting
to the mailing list in the past... Judging from
http://www.zsh.org/mla/workers/2017/msg00177.html I'm not the only one. Maybe
something can be done with the spam filter?  Thanks.

[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: Completion of swift fails when swift(1) is from Apple, not OpenStack
  2017-01-28 17:34 Completion of swift fails when swift(1) is from Apple, not OpenStack Zhiming Wang
  2017-01-28 17:42 ` Zhiming Wang
@ 2017-01-28 18:08 ` Bart Schaefer
  2017-01-28 19:54   ` Eric Cook
  2017-01-28 20:40   ` Zhiming Wang
  1 sibling, 2 replies; 6+ messages in thread
From: Bart Schaefer @ 2017-01-28 18:08 UTC (permalink / raw)
  To: Zhiming Wang; +Cc: Zsh hackers list

On Sat, 28 Jan 2017, Zhiming Wang wrote:

> Now that the conflict is obvious, I wonder what's the best course of
> action.

Probably the right thing is to add _swift, and use _pick_variant to choose
whether to call _openstack or to complete Apple's compiler options.


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

* Re: Completion of swift fails when swift(1) is from Apple, not OpenStack
  2017-01-28 18:08 ` Bart Schaefer
@ 2017-01-28 19:54   ` Eric Cook
  2017-01-28 20:40   ` Zhiming Wang
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Cook @ 2017-01-28 19:54 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 151 bytes --]

Here is a swing at giving filename completion, i don't have access to os x
or openstack to really test it or add actual completion for apple's swift.


[-- Attachment #2: 0001-create-stub-swift-function.patch --]
[-- Type: text/x-patch, Size: 1593 bytes --]

>From 59a1296b6e154974324cc6109cec4943f66fbeec Mon Sep 17 00:00:00 2001
From: Eric Cook <llua@gmx.com>
Date: Sat, 28 Jan 2017 14:49:53 -0500
Subject: [PATCH] create stub swift function

---
 Completion/Unix/Command/_openstack |  2 +-
 Completion/Unix/Command/_swift     | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 Completion/Unix/Command/_swift

diff --git a/Completion/Unix/Command/_openstack b/Completion/Unix/Command/_openstack
index 39fa30c..69e4921 100644
--- a/Completion/Unix/Command/_openstack
+++ b/Completion/Unix/Command/_openstack
@@ -1,4 +1,4 @@
-#compdef openstack aodh barbican ceilometer cinder cloudkitty designate glance gnocchi heat ironic keystone magnum manila mistral monasca murano neutron nova sahara senlin swift trove
+#compdef openstack aodh barbican ceilometer cinder cloudkitty designate glance gnocchi heat ironic keystone magnum manila mistral monasca murano neutron nova sahara senlin trove
 
 # https://wiki.openstack.org/wiki/OpenStackClients
 # http://docs.openstack.org/user-guide/common/cli-install-openstack-command-line-clients.html
diff --git a/Completion/Unix/Command/_swift b/Completion/Unix/Command/_swift
new file mode 100644
index 0000000..b29cc35
--- /dev/null
+++ b/Completion/Unix/Command/_swift
@@ -0,0 +1,13 @@
+#compdef swift
+
+local variant ret=1
+if _pick_variant -r variant apple='OVERVIEW: Swift compiler' openstack --help; then
+  case $variant in
+    apple)
+      _call_function ret _default;;
+    openstack)
+      _call_function ret _openstack;;
+  esac
+
+  return ret
+fi
-- 
2.9.2


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

* Re: Completion of swift fails when swift(1) is from Apple, not OpenStack
  2017-01-28 18:08 ` Bart Schaefer
  2017-01-28 19:54   ` Eric Cook
@ 2017-01-28 20:40   ` Zhiming Wang
  2017-01-28 20:52     ` Zhiming Wang
  1 sibling, 1 reply; 6+ messages in thread
From: Zhiming Wang @ 2017-01-28 20:40 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 7707 bytes --]

On Jan 28, 2017, at 1:08 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> 
> Probably the right thing is to add _swift, and use _pick_variant to choose
> whether to call _openstack or to complete Apple's compiler options.

Good call. I am attaching an implementation of _swift. Though I'd very much like
to parse --help output programmatically, some intricacies (like which options
can be repeated) are simply not visible from --help, so I'm hard coding options.
Hopefully Swift is stable enough that options won't fluctuate much across
versions.


From 0be3d1c9ac83bc46e8ce30ee5f0220bfca97395e Mon Sep 17 00:00:00 2001
From: Zhiming Wang <zmwangx@gmail.com>
Date: Sat, 28 Jan 2017 15:33:45 -0500
Subject: [PATCH] Completion/Unix/Command/_swift: new swift/swiftc completions

swift(1) and swiftc(1) are part of the Swift programming language.
https://swift.org/

_swift was written against Apple Swift version 3.0.2.

Note that swift(1) conflicts with the command of the same name from OpenStack.
Completion is delegated to _openstack when swift(1) is detected to be from
OpenStack.
---
 Completion/Unix/Command/_swift | 123 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 123 insertions(+)
 create mode 100644 Completion/Unix/Command/_swift

diff --git a/Completion/Unix/Command/_swift b/Completion/Unix/Command/_swift
new file mode 100644
index 000000000..6776f0dea
--- /dev/null
+++ b/Completion/Unix/Command/_swift
@@ -0,0 +1,123 @@
+#compdef swift swiftc
+
+# swift(1) and swiftc(1) are part of the Swift programming language.
+# https://swift.org/
+
+local -a common_options swiftc_mode_options swiftc_additional_options
+local -A swiftc_modes
+
+common_options=(
+  '-assert-config[specify the assert_configuration replacement]:config:(Debug Release Unchecked DisableReplacement)'
+  '*-D[marks a conditional compilation flag as true]:flag:'
+  '*-framework[specifies a framework which should be linked against]:framework:'
+  '*-F[add directory to framework search path]:path:_files -/'
+  '(-gnone)-gdwarf-types[emit full DWARF type info]'
+  '(-gnone)-gline-tables-only[emit minimal debug info for backtraces only]'
+  '(-gdwarf-types -gline-tables-only -g)-gnone[do not emit debug info]'
+  '(-gnone)-g[emit debug info]'
+  '(- : *)-help[display available options]'
+  '-index-store-path[store indexing data to the specified path]:directory:_files -/'
+  '*-I[add directory to the import search path]:path:_files -/'
+  '-j[number of commands to execute in parallel]:count:'
+  '*-L[add directory to library link search path]:path:_files -/'
+  '*-l-[specifies a library which should be linked against]:library:'
+  '-module-cache-path[specifies the Clang module cache path]:path:_files -/'
+  '-module-link-name[library to link against when using this module]:name:'
+  '-module-name[name of the module to build]:name:'
+  '-nostdimport[do not search the standard library import path for modules]'
+  '-num-threads[enable multi-threading and specify number of threads]:count:'
+  '(-Ounchecked -O)-Onone[compile without any optimization]'
+  '(-Onone)-Ounchecked[compile with optimizations and remove runtime safety checks]'
+  '(-Onone)-O[compile with optimizations]'
+  '-sdk[compile against SDK]:sdk:_files -/'
+  '-static-stdlib[statically link the Swift standard library]'
+  '-suppress-warnings[suppress all warnings]'
+  '-target-cpu[generate code for a particular CPU variant]:cpu'
+  '-target[generate code for the given target]:target'
+  '-use-ld=-[specifies the linker to be used]:linker:_files -/'
+  '(- : *)-version[print version information and exit]'
+  '-v[show commands to run and use verbose output]'
+  '-warnings-as-errors[treat warnings as errors]'
+  '*-Xcc[pass argument to the C/C++/Objective-C compiler]:arg:'
+  '*-Xlinker[specifies an option which should be passed to the linker]:option:'
+)
+
+swiftc_modes=(
+  -dump-ast        'parse and type-check input file(s) and dump AST(s)'
+  -dump-parse      'parse input file(s) and dump AST(s)'
+  -dump-type-refinement-contexts
+                   'type-check input file(s) and dump type refinement contexts(s)'
+  -emit-assembly   'emit assembly file(s) (-S)'
+  -emit-bc         'emit LLVM BC file(s)'
+  -emit-executable 'emit a linked executable'
+  -emit-ir         'emit LLVM IR file(s)'
+  -emit-library    'emit a linked library'
+  -emit-object     'emit object file(s) (-c)'
+  -emit-sibgen     'emit serialized AST + raw SIL file(s)'
+  -emit-sib        'emit serialized AST + canonical SIL file(s)'
+  -emit-silgen     'emit raw SIL file(s)'
+  -emit-sil        'emit canonical SIL file(s)'
+  -parse           'parse input file(s)'
+  -print-ast       'parse and type-check input file(s) and pretty print AST(s)'
+)
+local mode
+for mode in ${(k)swiftc_modes}; do
+  # Mode options are mutually exclusive
+  swiftc_mode_options+=("(${(k)swiftc_modes})${mode}[$swiftc_modes[$mode]]")
+done
+
+swiftc_additional_options=(
+  '-application-extension[restrict code to those available for App Extensions]'
+  '-embed-bitcode-marker[embed placeholder LLVM IR data as a marker]'
+  '-embed-bitcode[embed LLVM IR bitcode as data]'
+  '-emit-dependencies[emit basic Make-compatible dependencies files]'
+  '-emit-module-path[emit an importable module to the specified path]:path:_files -/'
+  '-emit-module[emit an importable module]'
+  '-emit-objc-header-path[emit an Objective-C header file to the specified path]:path:_files -/'
+  '-emit-objc-header[emit an Objective-C header file]'
+  '-fixit-all[apply all fixits from diagnostics without any filtering]'
+  '-fixit-code[get compiler fixits as code edits]'
+  '-import-underlying-module[implicitly imports the Objective-C half of a module]'
+  '-output-file-map[a file which specifies the location of outputs]:path:_files'
+  '-o[write output to specified file]:path:_files'
+  '-parse-as-library[parse the input file(s) as libraries, not scripts]'
+  '-parse-sil[parse the input file as SIL code, not Swift source]'
+  '-parseable-output[emit textual output in a parseable format]'
+  '-profile-coverage-mapping[generate coverage data for use with profiled execution counts]'
+  '-profile-generate[generate instrumented code to collect execution counts]'
+  '-sanitize-coverage=-[specify the type of coverage instrumentation for Sanitizers and additional options separated by commas]:type:'
+  '*-sanitize=-[turn on runtime checks for erroneous behavior]:check:'
+  '-save-temps[save intermediate compilation results]'
+  '-serialize-diagnostics[serialize diagnostics in a binary format]'
+  '-tools-directory[look for external executables (ld, clang, binutils) in the specified directory]:directory:_files -/'
+  '-whole-module-optimization[optimize input files together instead of individually]'
+)
+
+case "$words[1]" in
+  swift)
+    # The name swift conflicts with the command with the same name from the
+    # OpenStack project. We delegate completion to _openstack if swift(1) is
+    # detected to be from OpenStack.
+    local variant
+    _pick_variant -r variant openstack=OpenStack swiftlang='Swift compiler' unknown --help
+    case $variant in
+      openstack)
+        _openstack "$@"
+        ;;
+      swiftlang)
+        _arguments \
+            "$common_options[@]" \
+            '*:input:_files'
+        ;;
+      *)
+        _default "$@"
+    esac
+    ;;
+  swiftc)
+    _arguments \
+        "$swiftc_mode_options[@]" \
+        "$common_options[@]" \
+        "$swiftc_additional_options[@]" \
+        '*:input:_files'
+    ;;
+esac
--
2.11.0



[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: Completion of swift fails when swift(1) is from Apple, not OpenStack
  2017-01-28 20:40   ` Zhiming Wang
@ 2017-01-28 20:52     ` Zhiming Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Zhiming Wang @ 2017-01-28 20:52 UTC (permalink / raw)
  To: Zhiming Wang; +Cc: Bart Schaefer, Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 822 bytes --]

Just noticed I forgot to unregister swift in _openstack in the patch above.


diff --git a/Completion/Unix/Command/_openstack b/Completion/Unix/Command/_openstack
index 39fa30c3a..69e492156 100644
--- a/Completion/Unix/Command/_openstack
+++ b/Completion/Unix/Command/_openstack
@@ -1,4 +1,4 @@
-#compdef openstack aodh barbican ceilometer cinder cloudkitty designate glance gnocchi heat ironic keystone magnum manila mistral monasca murano neutron nova sahara senlin swift trove
+#compdef openstack aodh barbican ceilometer cinder cloudkitty designate glance gnocchi heat ironic keystone magnum manila mistral monasca murano neutron nova sahara senlin trove

 # https://wiki.openstack.org/wiki/OpenStackClients
 # http://docs.openstack.org/user-guide/common/cli-install-openstack-command-line-clients.html


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

end of thread, other threads:[~2017-01-28 20:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-28 17:34 Completion of swift fails when swift(1) is from Apple, not OpenStack Zhiming Wang
2017-01-28 17:42 ` Zhiming Wang
2017-01-28 18:08 ` Bart Schaefer
2017-01-28 19:54   ` Eric Cook
2017-01-28 20:40   ` Zhiming Wang
2017-01-28 20:52     ` Zhiming Wang

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).