1a657c6c4d44dbfcffb4c633a58e623f4d692706

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

yarn: use zsh-completions completion (ff73f40)

Version: ff73f40 (2018-05-02)

Fixes #5859
Fixes #5878
Fixes #5983
Fixes #6013

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/yarn/_yarn b/plugins/yarn/_yarn
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..382f58a0abacde5beb4836459a37a71d4d26440c
  4--- /dev/null
  5+++ b/plugins/yarn/_yarn
  6@@ -0,0 +1,345 @@
  7+#compdef yarn
  8+# ------------------------------------------------------------------------------
  9+# Redistribution and use in source and binary forms, with or without
 10+# modification, are permitted provided that the following conditions are met:
 11+#     * Redistributions of source code must retain the above copyright
 12+#       notice, this list of conditions and the following disclaimer.
 13+#     * Redistributions in binary form must reproduce the above copyright
 14+#       notice, this list of conditions and the following disclaimer in the
 15+#       documentation and/or other materials provided with the distribution.
 16+#     * Neither the name of the zsh-users nor the
 17+#       names of its contributors may be used to endorse or promote products
 18+#       derived from this software without specific prior written permission.
 19+#
 20+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 21+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 22+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 23+# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
 24+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 25+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 26+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 27+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 28+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 29+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30+# ------------------------------------------------------------------------------
 31+# Description
 32+# -----------
 33+#
 34+#  Completion script for yarn (https://yarnpkg.com/)
 35+#
 36+# ------------------------------------------------------------------------------
 37+# Authors
 38+# -------
 39+#
 40+#  * Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
 41+#
 42+# ------------------------------------------------------------------------------
 43+
 44+_commands=(
 45+  'access'
 46+  'autoclean:Clean and remove unnecessary files from package dependencies'
 47+  'cache:List or clean every cached package'
 48+  "check:Verify package dependencies agains yarn's lock file"
 49+  'config:Manages the yarn configuration files'
 50+  'generate-lock-entry:Generates a lock file entry'
 51+  'global:Install packages globally on your operating system'
 52+  'help:Show information about a command'
 53+  'import:Generate yarn.lock from an existing npm-installed node_modules folder'
 54+  'info:Show information about a package'
 55+  'init:Interactively creates or updates a package.json file'
 56+  'install:Install all the dependencies listed within package.json'
 57+  'licenses:List licenses for installed packages'
 58+  'link:Symlink a package folder during development'
 59+  'list:List installed packages'
 60+  'login:Store registry username and email'
 61+  'logout:Clear registry username and email'
 62+  'outdated:Check for outdated package dependencies'
 63+  'owner:Manage package owners'
 64+  'pack:Create a compressed gzip archive of package dependencies'
 65+  'publish:Publish a package to the npm registry'
 66+  'run:Run a defined package script'
 67+  'tag:Add, remove, or list tags on a package'
 68+  'team:Maintain team memberships'
 69+  'unlink:Unlink a previously created symlink for a package'
 70+  'version:Update the package version'
 71+  'versions:Display version information of currently installed Yarn, Node.js, and its dependencies'
 72+  'why:Show information about why a package is installed'
 73+)
 74+
 75+_global_commands=(
 76+  'add:Installs a package and any packages that it depends on'
 77+  'bin:Displays the location of the yarn bin folder'
 78+  'remove:Remove installed package from dependencies updating package.json'
 79+  'upgrade:Upgrades packages to their latest version based on the specified range'
 80+  'upgrade-interactive'
 81+)
 82+
 83+_yarn_commands_scripts() {
 84+  local -a scripts
 85+  scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
 86+  _describe 'command or script' _commands -- _global_commands -- scripts
 87+}
 88+
 89+_yarn_scripts() {
 90+  local -a scripts
 91+  scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
 92+  _describe 'script' scripts
 93+}
 94+
 95+_yarn_global_commands() {
 96+  local -a cmds
 97+  cmds=('ls:List installed packages')
 98+  _describe 'command' _global_commands
 99+}
100+
101+_yarn_commands() {
102+  _describe 'command' _commands -- _global_commands
103+}
104+
105+_yarn() {
106diff --git a/plugins/yarn/yarn.plugin.zsh b/plugins/yarn/yarn.plugin.zsh
107index eee811b16100a86e9800fabc7d1f3ad8d9dd73f8..7a9a7e4d4f1cb3840fc5aac783b42b16cbdd716b 100644
108--- a/plugins/yarn/yarn.plugin.zsh
109+++ b/plugins/yarn/yarn.plugin.zsh
110@@ -1,98 +1,6 @@
111-# Alias sorted alphabetically
112-
113 alias y="yarn "
114 alias ya="yarn add"
115 alias ycc="yarn cache clean"
116 alias yh="yarn help"
117 alias yout="yarn outdated"
118 alias yui="yarn upgrade-interactive"
119-
120-_yarn ()
121-{
122-    local -a _1st_arguments _dopts _dev _production
123-    local expl
124-    typeset -A opt_args
125-
126-    _dopts=(
127-        '(--force)--force[This refetches all packages, even ones that were previously installed.]'
128-    )
129-
130-    _installopts=(
131-        '(--flat)--flat[Only allow one version of a package. On the first run this will prompt you to choose a single version for each package that is depended on at multiple version ranges.]'
132-        '(--har)--har[Outputs an HTTP archive from all the network requests performed during the installation.]'
133-        '(--no-lockfile)--no-lockfile[Don’t read or generate a yarn.lock lockfile.]'
134-        '(--pure-lockfile)--pure-lockfile[Don’t generate a yarn.lock lockfile.]'
135-    )
136-
137-    _dev=('(--dev)--dev[Save installed packages into the project"s package.json devDependencies]')
138-
139-    _production=('(--production)--production[Do not install project devDependencies]')
140-
141-    _upgrade=(
142-        '(--exact)--exact[Install exact version]'
143-        '(--tilde)--tilde[Install most recent release with the same minor version]'
144-     )
145-
146-    _1st_arguments=(
147-      'help:Display help information about yarn' \
148-      'init:Initialize for the development of a package' \
149-      'add:Add a package to use in your current package' \
150-      'install:Install all the dependencies listed within package.json in the local node_modules folder' \
151-      'publish:Publish a package to a package manager' \
152-      'remove:Remove a package that will no longer be used in your current package' \
153-      'cache:Clear the local cache. It will be populated again the next time yarn or yarn install is run' \
154-      'clean:Frees up space by removing unnecessary files and folders from dependencies' \
155-      'check:Verifies that versions of the package dependencies in the current project’s package.json matches that of yarn’s lock file' \
156-      'ls:List all installed packages' \
157-      'global:Makes binaries available to use on your operating system' \
158-      'info:<package> [<field>] - fetch information about a package and return it in a tree format' \
159-      'outdated:Checks for outdated package dependencies' \
160-      'run:Runs a defined package script' \
161-      'self-update:Updates Yarn to the latest version' \
162-      'upgrade:Upgrades packages to their latest version based on the specified range' \
163-      'upgrade-interactive:Selectively upgrades specific packages in a simple way' \
164-      'why:<query> - Show information about why a package is installed'
165-    )
166-    _arguments \
167-    '*:: :->subcmds' && return 0
168-
169-    if (( CURRENT == 1 )); then
170-        _describe -t commands "yarn subcommand" _1st_arguments
171-        return
172-    fi
173-
174-    case "$words[1]" in
175-        add)
176-        _arguments \
177-        $_dopts \
178-        $_dev \
179-        $_production
180-        ;;
181-        install)
182-        _arguments \
183-        $_installopts \
184-        $_dopts \
185-        $_dev \
186-        $_no_color \
187-        $_production
188-        ;;
189-        update)
190-        _arguments \
191-        $_dopts
192-        ;;
193-        remove)
194-        _arguments \
195-        $_dopts
196-        ;;
197-        upgrade-interactive)
198-        _arguments \
199-        $_upgrade
200-        ;;
201-        *)
202-        _arguments \
203-        ;;
204-    esac
205-
206-}
207-
208-compdef _yarn yarn