4f4162c7fa5700dd7d0d15f150e8a29b5175c601
[stack/conf/vim.git] / addons / TagHighlight / plugin / TagHighlight / module / cmd.py
1 #!/usr/bin/env python
2 # Tag Highlighter:
3 #   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
4 # Copyright: Copyright (C) 2009-2011 A. S. Budden
5 #            Permission is hereby granted to use and distribute this code,
6 #            with or without modifications, provided that this copyright
7 #            notice is copied with it. Like anything else that's free,
8 #            the TagHighlight plugin is provided *as is* and comes with no
9 #            warranty of any kind, either expressed or implied. By using
10 #            this plugin, you agree that in no event will the copyright
11 #            holder be liable for any damages resulting from the use
12 #            of this software.
13
14 # ---------------------------------------------------------------------
15 from __future__ import print_function
16
17 import os
18 import optparse
19
20 from .config import SetInitialOptions, LoadLanguages
21 from .options import AllOptions
22
23 def ProcessCommandLine():
24     parser = optparse.OptionParser()
25
26     for dest in AllOptions.keys():
27         if 'CommandLineSwitches' not in AllOptions[dest]:
28             # Vim-only option
29             continue
30         if AllOptions[dest]['Type'] == 'bool':
31             if AllOptions[dest]['Default'] == True:
32                 action = 'store_false'
33             else:
34                 action = 'store_true'
35             parser.add_option(*AllOptions[dest]['CommandLineSwitches'],
36                     action=action,
37                     default=AllOptions[dest]['Default'],
38                     dest=dest,
39                     help=AllOptions[dest]['Help'])
40         else:
41             optparse_type='string'
42             if AllOptions[dest]['Type'] in ['string', 'int']:
43                 action='store'
44             elif AllOptions[dest]['Type'] == 'list':
45                 action='append'
46             else:
47                 raise Exception('Unrecognised option type: ' + AllOptions[dest]['Type'])
48             parser.add_option(*AllOptions[dest]['CommandLineSwitches'],
49                     action=action,
50                     default=AllOptions[dest]['Default'],
51                     type=optparse_type,
52                     dest=dest,
53                     help=AllOptions[dest]['Help'])
54
55     options, remainder = parser.parse_args()
56
57     return vars(options)