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)
| 6232 | |
| 6233 | |
| 6234 | def ParseArguments(args): |
| 6235 | """Parses the command line arguments. |
| 6236 | |
| 6237 | This may set the output format and verbosity level as side-effects. |
| 6238 | |
| 6239 | Args: |
| 6240 | args: The command line arguments: |
| 6241 | |
| 6242 | Returns: |
| 6243 | The list of filenames to lint. |
| 6244 | """ |
| 6245 | try: |
| 6246 | (opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=', |
| 6247 | 'counting=', |
| 6248 | 'filter=', |
| 6249 | 'root=', |
| 6250 | 'linelength=', |
| 6251 | 'extensions=']) |
| 6252 | except getopt.GetoptError: |
| 6253 | PrintUsage('Invalid arguments.') |
| 6254 | |
| 6255 | verbosity = _VerboseLevel() |
| 6256 | output_format = _OutputFormat() |
| 6257 | filters = '' |
| 6258 | counting_style = '' |
| 6259 | |
| 6260 | for (opt, val) in opts: |
| 6261 | if opt == '--help': |
| 6262 | PrintUsage(None) |
| 6263 | elif opt == '--output': |
| 6264 | if val not in ('emacs', 'vs7', 'eclipse'): |
| 6265 | PrintUsage('The only allowed output formats are emacs, vs7 and eclipse.') |
| 6266 | output_format = val |
| 6267 | elif opt == '--verbose': |
| 6268 | verbosity = int(val) |
| 6269 | elif opt == '--filter': |
| 6270 | filters = val |
| 6271 | if not filters: |
| 6272 | PrintCategories() |
| 6273 | elif opt == '--counting': |
| 6274 | if val not in ('total', 'toplevel', 'detailed'): |
| 6275 | PrintUsage('Valid counting options are total, toplevel, and detailed') |
| 6276 | counting_style = val |
| 6277 | elif opt == '--root': |
| 6278 | global _root |
| 6279 | _root = val |
| 6280 | elif opt == '--linelength': |
| 6281 | global _line_length |
| 6282 | try: |
| 6283 | _line_length = int(val) |
| 6284 | except ValueError: |
| 6285 | PrintUsage('Line length must be digits.') |
| 6286 | elif opt == '--extensions': |
| 6287 | global _valid_extensions |
| 6288 | try: |
| 6289 | _valid_extensions = set(val.split(',')) |
| 6290 | except ValueError: |
| 6291 | PrintUsage('Extensions must be comma seperated list.') |
no test coverage detected