From 85de9d4f16c5dfce67019c13a3056a2b7d6253d2 Mon Sep 17 00:00:00 2001 From: Sergei Silnov Date: Fri, 26 Jun 2020 17:18:25 +0200 Subject: [PATCH] idf.py: Add help for options with envvar defaults --- tools/idf.py | 7 +++---- tools/idf_py_actions/core_ext.py | 28 ++++++++++++++-------------- tools/idf_py_actions/serial_ext.py | 4 ++-- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/tools/idf.py b/tools/idf.py index 0c295feff4..31c78451a5 100755 --- a/tools/idf.py +++ b/tools/idf.py @@ -144,7 +144,6 @@ def init_cli(verbose_output=None): class Deprecation(object): """Construct deprecation notice for help messages""" - def __init__(self, deprecated=False): self.deprecated = deprecated self.since = None @@ -292,7 +291,6 @@ def init_cli(verbose_output=None): names - alias of 'param_decls' """ - def __init__(self, **kwargs): names = kwargs.pop("names") super(Argument, self).__init__(names, **kwargs) @@ -331,7 +329,6 @@ def init_cli(verbose_output=None): class Option(click.Option): """Option that knows whether it should be global""" - def __init__(self, scope=None, deprecated=False, hidden=False, **kwargs): """ Keyword arguments additional to Click's Option class: @@ -355,6 +352,9 @@ def init_cli(verbose_output=None): deprecation = Deprecation(deprecated) self.help = deprecation.help(self.help) + if self.envvar: + self.help += " The default value can be set with the %s environment variable." % self.envvar + if self.scope.is_global: self.help += " This option can be used at most once either globally, or for one subcommand." @@ -367,7 +367,6 @@ def init_cli(verbose_output=None): class CLI(click.MultiCommand): """Action list contains all actions with options available for CLI""" - def __init__(self, all_actions=None, verbose_output=None, help=None): super(CLI, self).__init__( chain=True, diff --git a/tools/idf_py_actions/core_ext.py b/tools/idf_py_actions/core_ext.py index bb2a76280e..056f652928 100644 --- a/tools/idf_py_actions/core_ext.py +++ b/tools/idf_py_actions/core_ext.py @@ -194,14 +194,14 @@ def action_extensions(base_actions, project_path): "help": "Show IDF version and exit.", "is_flag": True, "expose_value": False, - "callback": idf_version_callback + "callback": idf_version_callback, }, { "names": ["--list-targets"], "help": "Print list of supported targets and exit.", "is_flag": True, "expose_value": False, - "callback": list_targets_callback + "callback": list_targets_callback, }, { "names": ["-C", "--project-dir"], @@ -227,7 +227,7 @@ def action_extensions(base_actions, project_path): "is_flag": True, "is_eager": True, "default": False, - "callback": verbose_callback + "callback": verbose_callback, }, { "names": ["--preview"], @@ -237,11 +237,10 @@ def action_extensions(base_actions, project_path): }, { "names": ["--ccache/--no-ccache"], - "help": ( - "Use ccache in build. Disabled by default, unless " - "IDF_CCACHE_ENABLE environment variable is set to a non-zero value."), + "help": "Use ccache in build. Disabled by default.", "is_flag": True, - "default": os.getenv("IDF_CCACHE_ENABLE") not in [None, "", "0"], + "envvar": "IDF_CCACHE_ENABLE", + "default": False, }, { "names": ["-G", "--generator"], @@ -253,7 +252,7 @@ def action_extensions(base_actions, project_path): "help": "Only process arguments, but don't execute actions.", "is_flag": True, "hidden": True, - "default": False + "default": False, }, ], "global_action_callbacks": [validate_root_options], @@ -291,14 +290,15 @@ def action_extensions(base_actions, project_path): "names": ["--style", "--color-scheme", "style"], "help": ( "Menuconfig style.\n" - "Is it possible to customize the menuconfig style by either setting the MENUCONFIG_STYLE " - "environment variable or through this option. The built-in styles include:\n\n" + "The built-in styles include:\n\n" "- default - a yellowish theme,\n\n" - "- monochrome - a black and white theme, or\n" + "- monochrome - a black and white theme, or\n\n" "- aquatic - a blue theme.\n\n" - "The default value is \"aquatic\". It is possible to customize these themes further " - "as it is described in the Color schemes section of the kconfiglib documentation."), - "default": os.environ.get('MENUCONFIG_STYLE', 'aquatic'), + "It is possible to customize these themes further" + " as it is described in the Color schemes section of the kconfiglib documentation.\n" + 'The default value is \"aquatic\".'), + "envvar": "MENUCONFIG_STYLE", + "default": "aquatic", } ], }, diff --git a/tools/idf_py_actions/serial_ext.py b/tools/idf_py_actions/serial_ext.py index 4deb379a7f..ea20b9dad8 100644 --- a/tools/idf_py_actions/serial_ext.py +++ b/tools/idf_py_actions/serial_ext.py @@ -134,7 +134,7 @@ def action_extensions(base_actions, project_path): baud_rate = { "names": ["-b", "--baud"], - "help": "Baud rate for flashing. The default value can be set with the ESPBAUD environment variable.", + "help": "Baud rate for flashing.", "scope": "global", "envvar": "ESPBAUD", "default": 460800, @@ -142,7 +142,7 @@ def action_extensions(base_actions, project_path): port = { "names": ["-p", "--port"], - "help": "Serial port. The default value can be set with the ESPPORT environment variable.", + "help": "Serial port.", "scope": "global", "envvar": "ESPPORT", "default": None,