]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/args.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / args.vim
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: This module implements a function for parsing arguments for
3 " commands.
4
5 " Given a list of valid arguments like ['foo', 'bar'] and a string to parse,
6 " parse the arguments from the string and return [parsed_args, remainder].
7 "
8 " Arguments must be prefixed in the string with a single minus (-), and a
9 " double minus (--) denotes the end of arguments.
10 function! ale#args#Parse(arg_list, string) abort
11     let l:parsed = {}
12     let l:end_of_args = 0
13     let l:word_list = split(a:string, ' ')
14     let l:index = 0
15
16     while l:index < len(l:word_list)
17         let l:word = l:word_list[l:index]
18
19         if l:word[:0] is# '-'
20             let l:index += 1
21
22             if l:word is# '--'
23                 break
24             endif
25
26             let l:arg = l:word[1:]
27
28             if index(a:arg_list, l:arg) >= 0
29                 let l:parsed[l:arg] = ''
30             else
31                 throw 'Invalid argument: ' . l:word
32             endif
33         elseif l:word is# ''
34             let l:index += 1
35         else
36             break
37         endif
38     endwhile
39
40     let l:new_string = join(l:word_list[l:index :], ' ')
41
42     return [l:parsed, l:new_string]
43 endfunction