idf.py: Add help for options with envvar defaults

This commit is contained in:
Sergei Silnov 2020-06-26 17:18:25 +02:00
parent 7c5a5617a8
commit 85de9d4f16
3 changed files with 19 additions and 20 deletions

View File

@ -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,

View File

@ -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",
}
],
},

View File

@ -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,