c9841f43b1a95c6cc5fcca8422b47f8df511ecf6

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

Message

yarn: use zsh-completions latest version (87e1313)

Closes #7300
Closes #8115
Closes #8118

Diff

 1diff --git a/plugins/yarn/_yarn b/plugins/yarn/_yarn
 2index 382f58a0abacde5beb4836459a37a71d4d26440c..3689ae960d0e08af8a037cce3d95fafc78893377 100644
 3--- a/plugins/yarn/_yarn
 4+++ b/plugins/yarn/_yarn
 5@@ -71,7 +71,7 @@ _global_commands=(
 6   'bin:Displays the location of the yarn bin folder'
 7   'remove:Remove installed package from dependencies updating package.json'
 8   'upgrade:Upgrades packages to their latest version based on the specified range'
 9-  'upgrade-interactive'
10+  'upgrade-interactive:Interactively upgrade packages'
11 )
12 
13 _yarn_commands_scripts() {
14@@ -81,9 +81,21 @@ _yarn_commands_scripts() {
15 }
16 
17 _yarn_scripts() {
18-  local -a scripts
19-  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'))
20-  _describe 'script' scripts
21+  local -a commands binaries scripts
22+  local -a scriptNames scriptCommands
23+  local i runJSON
24+
25+  runJSON=$(yarn run --json 2>/dev/null)
26+  binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\n/g' <<< "$runJSON"))
27+  scriptNames=($(sed -E '/possibleCommands/!d;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\n/g' <<< "$runJSON"))
28+  scriptCommands=("${(@f)$(sed -E '/possibleCommands/!d;s/.*"hints":\{([^}]+)\}.*/\1/;s/"[^"]+"://g;s/:/\\:/g;s/","/\n/g;s/(^"|"$)//g' <<< "$runJSON")}")
29+
30+  for (( i=1; i <= $#scriptNames; i++ )); do
31+    scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}")
32+  done
33+
34+  commands=($scripts $binaries)
35+  _describe 'command' commands
36 }
37 
38 _yarn_global_commands() {
39@@ -240,7 +252,8 @@ _yarn() {
40 
41         run)
42           _arguments \
43-            '1: :_yarn_scripts'
44+            '1: :_yarn_scripts' \
45+            '*:: :_default'
46         ;;
47 
48         tag)
49@@ -255,6 +268,11 @@ _yarn() {
50             '*:: :->team_args'
51         ;;
52 
53+        upgrade-interactive)
54+          _arguments \
55+            '--latest:use the version tagged latest in the registry:'
56+        ;;
57+
58         version)
59           _arguments \
60             '--new-version:version:' \
61@@ -266,6 +284,10 @@ _yarn() {
62           _arguments \
63             '1:query:_files'
64         ;;
65+
66+        *) 
67+          _default
68+        ;;
69       esac
70     ;;
71   esac