History

gen_compile_commands: use choices for --log_levels option

Use 'choices' to check if the given parameter is valid. I also simplified the help message because, with 'choices', --help shows the list of valid parameters: --log_level {DEBUG,INFO,WARNING,ERROR,CRITICAL} I started the help message with a lower case, "the level of log ..." in order to be consistent with the -h option: -h, --help show this help message and exit The message "show this help ..." comes from the ArgumentParser library code, and I do not know how to change it. So, I changed our code.

Masahiro Yamada committed 6 years ago

Commit ea6cedc1 parent 8a685db1 file · +4 −10Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/gen_compile_commands.py+4−10
@@ -45,24 +45,18 @@ def parse_arguments(): · 44 unmodified lines
4545 'compile_commands.json in the search directory)')
4646 parser.add_argument('-o', '--output', type=str, help=output_help)
4747
48− log_level_help = ('The level of log messages to produce (one of ' +
49− ', '.join(_VALID_LOG_LEVELS) + '; defaults to ' +
48+ log_level_help = ('the level of log messages to produce (defaults to ' +
5049 _DEFAULT_LOG_LEVEL + ')')
51− parser.add_argument(
52− '--log_level', type=str, default=_DEFAULT_LOG_LEVEL,
53− help=log_level_help)
50+ parser.add_argument('--log_level', choices=_VALID_LOG_LEVELS,
51+ default=_DEFAULT_LOG_LEVEL, help=log_level_help)
5452
5553 args = parser.parse_args()
5654
57− log_level = args.log_level
58− if log_level not in _VALID_LOG_LEVELS:
59− raise ValueError('%s is not a valid log level' % log_level)
60−
6155 directory = args.directory or os.getcwd()
6256 output = args.output or os.path.join(directory, _DEFAULT_OUTPUT)
6357 directory = os.path.abspath(directory)
6458
65− return log_level, directory, output
59+ return args.log_level, directory, output
6660
6761
6862 def process_line(root_directory, file_directory, command_prefix, relative_path):