Procházet zdrojové kódy

Change post-hook function to take a dictionary for more control

Junegunn Choi před 11 roky
rodič
revize
e6a594f1ad
3 změnil soubory, kde provedl 18 přidání a 11 odebrání
  1. 9 3
      README.md
  2. 3 2
      plug.vim
  3. 6 6
      test/workflow.vader

+ 9 - 3
README.md

@@ -129,11 +129,17 @@ In that case, use `do` option to describe the task to be performed.
 Plug 'Valloric/YouCompleteMe', { 'do': './install.sh' }
 ```
 
-If you need more control, you can pass a reference to a Vim function instead.
+If you need more control, you can pass a reference to a Vim function that
+takes a single argument.
 
 ```vim
-function! BuildYCM()
-  " ...
+function! BuildYCM(info)
+  " info is a dictionary with two fields
+  " - name: name of the plugin
+  " - status: 'installed' or 'updated'
+  if a:info.status == 'installed'
+    !./install.sh
+  endif
 endfunction
 
 Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') }

+ 3 - 2
plug.vim

@@ -454,7 +454,8 @@ function! s:do(pull, todo)
       continue
     endif
     execute 'cd '.s:esc(spec.dir)
-    if has_key(s:prev_update.new, name) || (a:pull &&
+    let installed = has_key(s:prev_update.new, name)
+    if installed || (a:pull &&
       \ !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"')))
       call append(3, '- Post-update hook for '. name .' ... ')
       let type = type(spec.do)
@@ -470,7 +471,7 @@ function! s:do(pull, todo)
         endtry
       elseif type == s:TYPE.funcref
         try
-          call spec.do()
+          call spec.do({ 'name': name, 'status': (installed ? 'installed' : 'updated') })
           let result = 'Done!'
         catch
           let result = 'Error: ' . v:exception

+ 6 - 6
test/workflow.vader

@@ -644,8 +644,8 @@ Execute (When already updated):
     \ 'vim-pseudocl/updated2 should exist'
 
 Execute (Using Funcref):
-  function! PlugUpdated()
-    call system('touch me')
+  function! PlugUpdated(info)
+    call system('touch '. a:info.name . a:info.status . len(a:info))
   endfunction
 
   call plug#begin()
@@ -659,10 +659,10 @@ Execute (Using Funcref):
   PlugUpdate
   Log getline(1, '$')
   q
-  Assert filereadable(g:plugs['vim-easy-align'].dir.'/me'),
-    \ 'vim-easy-align/me should exist'
-  Assert filereadable(g:plugs['vim-pseudocl'].dir.'/me'),
-    \ 'vim-pseudocl/me should exist'
+  Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignupdated2'),
+    \ 'vim-easy-align/vim-easy-alignupdated2 should exist'
+  Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclinstalled2'),
+    \ 'vim-pseudocl/vim-pseudoclinstalled2 should exist'
 
 Execute (Cleanup):
   call system('rm -rf '.temp_plugged)