File: args.vim

package info (click to toggle)
vim-ale 4.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,764 kB
  • sloc: sh: 499; python: 311; perl: 31; makefile: 4; xml: 4; javascript: 1
file content (43 lines) | stat: -rw-r--r-- 1,206 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
" Author: w0rp <devw0rp@gmail.com>
" Description: This module implements a function for parsing arguments for
" commands.

" Given a list of valid arguments like ['foo', 'bar'] and a string to parse,
" parse the arguments from the string and return [parsed_args, remainder].
"
" Arguments must be prefixed in the string with a single minus (-), and a
" double minus (--) denotes the end of arguments.
function! ale#args#Parse(arg_list, string) abort
    let l:parsed = {}
    let l:end_of_args = 0
    let l:word_list = split(a:string, ' ')
    let l:index = 0

    while l:index < len(l:word_list)
        let l:word = l:word_list[l:index]

        if l:word[:0] is# '-'
            let l:index += 1

            if l:word is# '--'
                break
            endif

            let l:arg = l:word[1:]

            if index(a:arg_list, l:arg) >= 0
                let l:parsed[l:arg] = ''
            else
                throw 'Invalid argument: ' . l:word
            endif
        elseif l:word is# ''
            let l:index += 1
        else
            break
        endif
    endwhile

    let l:new_string = join(l:word_list[l:index :], ' ')

    return [l:parsed, l:new_string]
endfunction