OLD | NEW |
1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public |
2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
4 | 4 |
5 import argparse | 5 import argparse |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import re | 8 import re |
9 import shutil | 9 import shutil |
10 import subprocess | 10 import subprocess |
(...skipping 21 matching lines...) Expand all Loading... |
32 parser.add_argument(*args, **kwargs) | 32 parser.add_argument(*args, **kwargs) |
33 | 33 |
34 return partial(_make_argument, *args, **kwargs) | 34 return partial(_make_argument, *args, **kwargs) |
35 | 35 |
36 | 36 |
37 def argparse_command(valid_platforms=None, multi_platform=False, arguments=()): | 37 def argparse_command(valid_platforms=None, multi_platform=False, arguments=()): |
38 def wrapper(func): | 38 def wrapper(func): |
39 def func_wrapper(*args, **kwargs): | 39 def func_wrapper(*args, **kwargs): |
40 return func(*args, **kwargs) | 40 return func(*args, **kwargs) |
41 | 41 |
42 short_desc, long_desc = func.__doc__.split(os.linesep + os.linesep, 1) | 42 short_desc, long_desc = func.__doc__.split('\n\n', 1) |
43 | 43 |
44 ALL_COMMANDS.append({ | 44 ALL_COMMANDS.append({ |
45 'name': func.__name__, | 45 'name': func.__name__, |
46 'description': long_desc, | 46 'description': long_desc, |
47 'help_text': short_desc, | 47 'help_text': short_desc, |
48 'valid_platforms': valid_platforms or KNOWN_PLATFORMS, | 48 'valid_platforms': valid_platforms or KNOWN_PLATFORMS, |
49 'multi_platform': multi_platform, | 49 'multi_platform': multi_platform, |
50 'function': func, | 50 'function': func, |
51 'arguments': arguments, | 51 'arguments': arguments, |
52 }) | 52 }) |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 if build_available_subcommands(base_dir): | 379 if build_available_subcommands(base_dir): |
380 MAIN_PARSER.set_defaults(base_dir=base_dir) | 380 MAIN_PARSER.set_defaults(base_dir=base_dir) |
381 | 381 |
382 # If no args are provided, this module is run directly from the command | 382 # If no args are provided, this module is run directly from the command |
383 # line. argparse will take care of consuming sys.argv. | 383 # line. argparse will take care of consuming sys.argv. |
384 arguments = MAIN_PARSER.parse_args(args if len(args) > 0 else None) | 384 arguments = MAIN_PARSER.parse_args(args if len(args) > 0 else None) |
385 | 385 |
386 function = arguments.function | 386 function = arguments.function |
387 del arguments.function | 387 del arguments.function |
388 function(**vars(arguments)) | 388 function(**vars(arguments)) |
OLD | NEW |