Parses the command line arguments. This may set the output format and verbosity level as side-effects. Args: args: The command line arguments: Returns: The list of filenames to lint.
(args)
| 6143 | |
| 6144 | |
| 6145 | def ParseArguments(args): |
| 6146 | """Parses the command line arguments. |
| 6147 | |
| 6148 | This may set the output format and verbosity level as side-effects. |
| 6149 | |
| 6150 | Args: |
| 6151 | args: The command line arguments: |
| 6152 | |
| 6153 | Returns: |
| 6154 | The list of filenames to lint. |
| 6155 | """ |
| 6156 | try: |
| 6157 | (opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=', |
| 6158 | 'counting=', |
| 6159 | 'filter=', |
| 6160 | 'root=', |
| 6161 | 'linelength=', |
| 6162 | 'extensions=', |
| 6163 | 'headers=', |
| 6164 | 'quiet']) |
| 6165 | except getopt.GetoptError: |
| 6166 | PrintUsage('Invalid arguments.') |
| 6167 | |
| 6168 | verbosity = _VerboseLevel() |
| 6169 | output_format = _OutputFormat() |
| 6170 | filters = '' |
| 6171 | quiet = _Quiet() |
| 6172 | counting_style = '' |
| 6173 | |
| 6174 | for (opt, val) in opts: |
| 6175 | if opt == '--help': |
| 6176 | PrintUsage(None) |
| 6177 | elif opt == '--output': |
| 6178 | if val not in ('emacs', 'vs7', 'eclipse'): |
| 6179 | PrintUsage('The only allowed output formats are emacs, vs7 and eclipse.') |
| 6180 | output_format = val |
| 6181 | elif opt == '--quiet': |
| 6182 | quiet = True |
| 6183 | elif opt == '--verbose': |
| 6184 | verbosity = int(val) |
| 6185 | elif opt == '--filter': |
| 6186 | filters = val |
| 6187 | if not filters: |
| 6188 | PrintCategories() |
| 6189 | elif opt == '--counting': |
| 6190 | if val not in ('total', 'toplevel', 'detailed'): |
| 6191 | PrintUsage('Valid counting options are total, toplevel, and detailed') |
| 6192 | counting_style = val |
| 6193 | elif opt == '--root': |
| 6194 | global _root |
| 6195 | _root = val |
| 6196 | elif opt == '--linelength': |
| 6197 | global _line_length |
| 6198 | try: |
| 6199 | _line_length = int(val) |
| 6200 | except ValueError: |
| 6201 | PrintUsage('Line length must be digits.') |
| 6202 | elif opt == '--extensions': |
no test coverage detected