diff --git a/tools/idf_size.py b/tools/idf_size.py index 80c968239a..a3cb75c7da 100755 --- a/tools/idf_size.py +++ b/tools/idf_size.py @@ -13,8 +13,13 @@ if __name__ == '__main__': # Here the argparse is used only to "peek" into arguments if # legacy version is requested or if old json format is specified. # In these two cases the esp_idf_size legacy version is spawned. - parser = argparse.ArgumentParser(exit_on_error=False, add_help=False) - parser.add_argument('--format') + parser = argparse.ArgumentParser(add_help=False) + # Make the --format arg optional, so this argparse instance does not + # fail with an error and the proper underlying help is displayed. + # Note that exit_on_error is supported from python3.9, so this is + # a workaround how to make sure that the args parsing doesn't fail here if idf_size.py + # is invoked e.g. without specifying the format, like "idf_size.py --format". + parser.add_argument('--format', nargs='?') parser.add_argument('-l', '--legacy', action='store_true', default=os.environ.get('ESP_IDF_SIZE_LEGACY', '0') == '1') # The sys.argv is parsed with "exit_on_error", but the argparse.ArgumentError @@ -34,7 +39,9 @@ if __name__ == '__main__': os.environ['ESP_IDF_SIZE_NG'] = '1' if not rest or '-h' in rest or '--help' in rest: print(('Note: legacy esp_idf_size version can be invoked by specifying the -l/--legacy ' - 'option or by setting the ESP_IDF_SIZE_LEGACY environment variable.')) + 'option or by setting the ESP_IDF_SIZE_LEGACY environment variable. Additionally, the ' + 'legacy version is automatically employed when the JSON format is specified for ' + 'compatibility with previous versions.')) if args.format is not None: rest = ['--format', args.format] + rest