Skip to content

Commit

Permalink
Merge pull request #26 from tsuyoshicho/fix/argcheck
Browse files Browse the repository at this point in the history
fix: function arg keyword change to list -> str
  • Loading branch information
tsuyoshicho authored May 28, 2019
2 parents bcd8ede + 1452162 commit 2ff1926
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
15 changes: 10 additions & 5 deletions autoload/pass.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ set cpo&vim
" API get
" return value
function! pass#get(entry, ...) abort
return pass#get#entry_value(a:entry, a:000)
let keyword = (a:0 > 0) ? a:1 : ''
return pass#get#entry_value(a:entry, keyword)
endfunction

" API get_otp
Expand All @@ -39,7 +40,8 @@ function! pass#get_register(entry, ...) abort
" set to register
" register clear timer(at expire timer.if register remain value,then clear)
" currently support unnamed register.
let @" = pass#get#entry_value(a:entry, a:000)
let keyword = (a:0 > 0) ? a:1 : ''
let @" = pass#get#entry_value(a:entry, keyword)
endfunction

" API get_otp_register
Expand All @@ -61,8 +63,9 @@ endfunction
" use only while startup.at end of start up,invoke passphrase input once.
" all waited process execute
function! pass#get_startup_funcall(func,entry, ...) abort
let keyword = (a:0 > 0) ? a:1 : ''
if v:vim_did_enter == 0
call pass#startup#entry_setup_funcall(a:func,a:entry,a:000)
call pass#startup#entry_setup_funcall(a:func, a:entry, keyword)
else
throw 'Already startup done.'
endif
Expand All @@ -72,8 +75,9 @@ endfunction
" use only while startup.at end of start up,invoke passphrase input once.
" all waited process execute
function! pass#get_startup_scope(scope,set_variable,entry, ...) abort
let keyword = (a:0 > 0) ? a:1 : ''
if v:vim_did_enter == 0
call pass#startup#entry_setup_letval(a:scope,a:set_variable,a:entry,a:000)
call pass#startup#entry_setup_letval(a:scope, a:set_variable, a:entry, keyword)
else
throw 'Already startup done.'
endif
Expand All @@ -83,8 +87,9 @@ endfunction
" use only while startup.at end of start up,invoke passphrase input once.
" all waited process execute
function! pass#get_startup(set_variable,entry, ...) abort
let keyword = (a:0 > 0) ? a:1 : ''
if v:vim_did_enter == 0
call pass#startup#entry_setup_letval(v:null,a:set_variable,a:entry,a:000)
call pass#startup#entry_setup_letval(v:null, a:set_variable, a:entry, keyword)
else
throw 'Already startup done.'
endif
Expand Down
6 changes: 3 additions & 3 deletions autoload/pass/get.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ let s:save_cpo = &cpo
set cpo&vim

" Vital
let s:Path = vital#vimpass#import('System.Filepath')
let s:Path = vital#vimpass#import('System.Filepath')

" get entry data
function! pass#get#entry_value(entry, keywords) abort
function! pass#get#entry_value(entry, keyword) abort
" get gpg-id
let gpgid = pass#get#id()
" get entry
Expand All @@ -26,7 +26,7 @@ function! pass#get#entry_value(entry, keywords) abort
endif

let passphrase = pass#get#passphrase()
let entry_value = pass#util#decode(gpgid, entrypath, passphrase, a:keywords)
let entry_value = pass#util#decode(gpgid, entrypath, passphrase, a:keyword)

return entry_value
endfunction
Expand Down
18 changes: 9 additions & 9 deletions autoload/pass/startup.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ let s:save_cpo = &cpo
set cpo&vim

" Vital
let s:List = vital#vimpass#import('Data.List')
let s:List = vital#vimpass#import('Data.List')

" variable
let s:pass_startup_request = []

function! pass#startup#entry_setup_letval(scope, set_variable, entry, keywords) abort
let Fn = function('s:letval_resolver',[a:scope,a:set_variable,a:entry,a:keywords])
function! pass#startup#entry_setup_letval(scope, set_variable, entry, keyword) abort
let Fn = function('s:letval_resolver',[a:scope,a:set_variable,a:entry,a:keyword])
call s:List.push(s:pass_startup_request, Fn)
endfunction

function! pass#startup#entry_setup_funcall(func, entry, keywords) abort
let Fn = function('s:funcall_resolver',[a:func,a:entry,a:keywords])
function! pass#startup#entry_setup_funcall(func, entry, keyword) abort
let Fn = function('s:funcall_resolver',[a:func,a:entry,a:keyword])
call s:List.push(s:pass_startup_request, Fn)
endfunction

Expand All @@ -40,8 +40,8 @@ function! pass#startup#resolve() abort
let s:pass_startup_request = []
endfunction

function! s:letval_resolver(scope,set_variable, entry, keywords) abort
let value = pass#get#entry_value(a:entry, a:keywords)
function! s:letval_resolver(scope,set_variable, entry, keyword) abort
let value = pass#get#entry_value(a:entry, a:keyword)

if v:null == a:scope
call execute('let ' . a:set_variable . '=' . "'" . value . "'")
Expand All @@ -50,8 +50,8 @@ function! s:letval_resolver(scope,set_variable, entry, keywords) abort
endif
endfunction

function! s:funcall_resolver(func, entry, keywords) abort
let value = pass#get#entry_value(a:entry, a:keywords)
function! s:funcall_resolver(func, entry, keyword) abort
let value = pass#get#entry_value(a:entry, a:keyword)

call call(a:func,[value])
endfunction
Expand Down
23 changes: 9 additions & 14 deletions autoload/pass/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ function! pass#util#completion(A,L,P) abort
endfunction

" value
function! pass#util#decode(gpgid, entrypath, passphrase, keywords) abort
function! pass#util#decode(gpgid, entrypath, passphrase, keyword) abort
let entrylist = s:decrypt_entry_gpg(a:gpgid, a:entrypath, a:passphrase)
return s:select_entry_value(entrylist, a:keywords)
return s:select_entry_value(entrylist, a:keyword)
endfunction

" execute command
Expand Down Expand Up @@ -70,41 +70,36 @@ endfunction

" select entry value
" input entry string list / return value string
function! s:select_entry_value(entrylist, keywords) abort
function! s:select_entry_value(entrylist, keyword) abort
let entrylist = a:entrylist

if empty(entrylist)
" no work
return ''
endif

if empty(a:keywords)
" need default -> first line password
return entrylist[0]
endif

let key = a:keywords[0]
let keyword = a:keyword
let keyname = ''
let keylist = [key]
let keylist = [keyword]

" password entry required.
let entry_altmap = extend(get(g:, 'pass_entry_altmap', {}),{
\ 'password' : ['password', 'secret'],
\}, "keep")

for [k,v] in items(entry_altmap)
if -1 != match(v, '\c\V' . escape(key,'\'))
if -1 != match(v, '\c\<' . escape(keyword,'\') . '\>')
let keyname = k
let keylist = v
break
endif
endfor

let retvalue = ''
if keyname == 'password'
if (keyword == '') || (keyname == 'password')
" need default -> first line password
let retvalue = entrylist[0]
elseif key == 'otp'
elseif keyword == 'otp'
" special value otpauth://
for e in entrylist[1:]
if 0 == match(e, '\c\V' . escape('otpauth://','\'))
Expand All @@ -113,7 +108,7 @@ function! s:select_entry_value(entrylist, keywords) abort
endif
endfor
else
" generate dict(key,value)
" generate dict(key, value)
let entrymap = {}

" ignore password(first line)
Expand Down

0 comments on commit 2ff1926

Please sign in to comment.