:Plug throws error for invalid option
This commit is contained in:
parent
71c41fccf5
commit
4fc2faf697
19
plug.vim
19
plug.vim
|
@ -632,17 +632,34 @@ function! plug#(repo, ...)
|
||||||
let g:plugs[name] = spec
|
let g:plugs[name] = spec
|
||||||
let s:loaded[name] = get(s:loaded, name, 0)
|
let s:loaded[name] = get(s:loaded, name, 0)
|
||||||
catch
|
catch
|
||||||
return s:err(v:exception)
|
return s:err(repo . ' ' . v:exception)
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:parse_options(arg)
|
function! s:parse_options(arg)
|
||||||
let opts = copy(s:base_spec)
|
let opts = copy(s:base_spec)
|
||||||
let type = type(a:arg)
|
let type = type(a:arg)
|
||||||
|
let opt_errfmt = 'Invalid argument for "%s" option of :Plug (expected: %s)'
|
||||||
if type == s:TYPE.string
|
if type == s:TYPE.string
|
||||||
|
if empty(a:arg)
|
||||||
|
throw printf(opt_errfmt, 'tag', 'string')
|
||||||
|
endif
|
||||||
let opts.tag = a:arg
|
let opts.tag = a:arg
|
||||||
elseif type == s:TYPE.dict
|
elseif type == s:TYPE.dict
|
||||||
call extend(opts, a:arg)
|
call extend(opts, a:arg)
|
||||||
|
for opt in ['branch', 'tag', 'commit', 'rtp', 'dir', 'as']
|
||||||
|
if has_key(opts, opt)
|
||||||
|
\ && (type(opts[opt]) != s:TYPE.string || empty(opts[opt]))
|
||||||
|
throw printf(opt_errfmt, opt, 'string')
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
for opt in ['on', 'for']
|
||||||
|
if has_key(opts, opt)
|
||||||
|
\ && type(opts[opt]) != s:TYPE.list
|
||||||
|
\ && (type(opts[opt]) != s:TYPE.string || empty(opts[opt]))
|
||||||
|
throw printf(opt_errfmt, opt, 'string or list')
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
if has_key(opts, 'dir')
|
if has_key(opts, 'dir')
|
||||||
let opts.dir = s:dirpath(s:plug_expand(opts.dir))
|
let opts.dir = s:dirpath(s:plug_expand(opts.dir))
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -49,11 +49,19 @@ Execute (Test Plug command):
|
||||||
AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch
|
AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch
|
||||||
|
|
||||||
^ Git repo with tag (DEPRECATED. USE TAG OPTION)
|
^ Git repo with tag (DEPRECATED. USE TAG OPTION)
|
||||||
|
redir => out
|
||||||
|
Plug 'foo/bar.vim', ''
|
||||||
|
redir END
|
||||||
|
Assert out =~ 'Invalid argument for "tag" option of :Plug (expected: string)'
|
||||||
Plug 'junegunn/goyo.vim', '1.5.2'
|
Plug 'junegunn/goyo.vim', '1.5.2'
|
||||||
AssertEqual 'file:///tmp/vim-plug-test/junegunn/goyo.vim', g:plugs['goyo.vim'].uri
|
AssertEqual 'file:///tmp/vim-plug-test/junegunn/goyo.vim', g:plugs['goyo.vim'].uri
|
||||||
AssertEqual join([g:temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir
|
AssertEqual join([g:temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir
|
||||||
AssertEqual '1.5.2', g:plugs['goyo.vim'].tag
|
AssertEqual '1.5.2', g:plugs['goyo.vim'].tag
|
||||||
|
|
||||||
|
redir => out
|
||||||
|
Plug 'foo/bar.vim', {'tag': ''}
|
||||||
|
redir END
|
||||||
|
Assert out =~ 'Invalid argument for "tag" option of :Plug (expected: string)'
|
||||||
Plug 'junegunn/goyo.vim', { 'tag': '1.5.3' } " Using tag option
|
Plug 'junegunn/goyo.vim', { 'tag': '1.5.3' } " Using tag option
|
||||||
AssertEqual '1.5.3', g:plugs['goyo.vim'].tag
|
AssertEqual '1.5.3', g:plugs['goyo.vim'].tag
|
||||||
|
|
||||||
|
@ -77,6 +85,18 @@ Execute (Test Plug command):
|
||||||
|
|
||||||
Execute (Plug command with dictionary option):
|
Execute (Plug command with dictionary option):
|
||||||
Log string(g:plugs)
|
Log string(g:plugs)
|
||||||
|
for opt in ['branch', 'tag', 'commit', 'rtp', 'dir', 'as']
|
||||||
|
redir => out
|
||||||
|
Plug 'foo/bar.vim', {opt: ''}
|
||||||
|
redir END
|
||||||
|
Assert out =~ 'Invalid argument for "'.opt.'" option of :Plug (expected: string)'
|
||||||
|
endfor
|
||||||
|
for opt in ['on', 'for']
|
||||||
|
redir => out
|
||||||
|
Plug 'foo/bar.vim', {opt: ''}
|
||||||
|
redir END
|
||||||
|
Assert out =~ 'Invalid argument for "'.opt.'" option of :Plug (expected: string or list)'
|
||||||
|
endfor
|
||||||
Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co', 'rtp': '././' }
|
Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co', 'rtp': '././' }
|
||||||
AssertEqual join([g:temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
|
AssertEqual join([g:temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
|
||||||
AssertEqual '././', g:plugs['seoul256.vim'].rtp
|
AssertEqual '././', g:plugs['seoul256.vim'].rtp
|
||||||
|
|
Loading…
Reference in New Issue
Block a user