Skip to content

Commit 096ec3e

Browse files
committed
Merge branch 'feature/idfpy_envvar_help' into 'master'
idf.py: Add help for all options with environment variables See merge request espressif/esp-idf!9356
2 parents 7a86681 + 85de9d4 commit 096ec3e

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

tools/idf.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def init_cli(verbose_output=None):
144144

145145
class Deprecation(object):
146146
"""Construct deprecation notice for help messages"""
147-
148147
def __init__(self, deprecated=False):
149148
self.deprecated = deprecated
150149
self.since = None
@@ -292,7 +291,6 @@ class Argument(click.Argument):
292291
293292
names - alias of 'param_decls'
294293
"""
295-
296294
def __init__(self, **kwargs):
297295
names = kwargs.pop("names")
298296
super(Argument, self).__init__(names, **kwargs)
@@ -331,7 +329,6 @@ def __str__(self):
331329

332330
class Option(click.Option):
333331
"""Option that knows whether it should be global"""
334-
335332
def __init__(self, scope=None, deprecated=False, hidden=False, **kwargs):
336333
"""
337334
Keyword arguments additional to Click's Option class:
@@ -355,6 +352,9 @@ def __init__(self, scope=None, deprecated=False, hidden=False, **kwargs):
355352
deprecation = Deprecation(deprecated)
356353
self.help = deprecation.help(self.help)
357354

355+
if self.envvar:
356+
self.help += " The default value can be set with the %s environment variable." % self.envvar
357+
358358
if self.scope.is_global:
359359
self.help += " This option can be used at most once either globally, or for one subcommand."
360360

@@ -367,7 +367,6 @@ def get_help_record(self, ctx):
367367

368368
class CLI(click.MultiCommand):
369369
"""Action list contains all actions with options available for CLI"""
370-
371370
def __init__(self, all_actions=None, verbose_output=None, help=None):
372371
super(CLI, self).__init__(
373372
chain=True,

tools/idf_py_actions/core_ext.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ def list_targets_callback(ctx, param, value):
194194
"help": "Show IDF version and exit.",
195195
"is_flag": True,
196196
"expose_value": False,
197-
"callback": idf_version_callback
197+
"callback": idf_version_callback,
198198
},
199199
{
200200
"names": ["--list-targets"],
201201
"help": "Print list of supported targets and exit.",
202202
"is_flag": True,
203203
"expose_value": False,
204-
"callback": list_targets_callback
204+
"callback": list_targets_callback,
205205
},
206206
{
207207
"names": ["-C", "--project-dir"],
@@ -227,7 +227,7 @@ def list_targets_callback(ctx, param, value):
227227
"is_flag": True,
228228
"is_eager": True,
229229
"default": False,
230-
"callback": verbose_callback
230+
"callback": verbose_callback,
231231
},
232232
{
233233
"names": ["--preview"],
@@ -237,11 +237,10 @@ def list_targets_callback(ctx, param, value):
237237
},
238238
{
239239
"names": ["--ccache/--no-ccache"],
240-
"help": (
241-
"Use ccache in build. Disabled by default, unless "
242-
"IDF_CCACHE_ENABLE environment variable is set to a non-zero value."),
240+
"help": "Use ccache in build. Disabled by default.",
243241
"is_flag": True,
244-
"default": os.getenv("IDF_CCACHE_ENABLE") not in [None, "", "0"],
242+
"envvar": "IDF_CCACHE_ENABLE",
243+
"default": False,
245244
},
246245
{
247246
"names": ["-G", "--generator"],
@@ -253,7 +252,7 @@ def list_targets_callback(ctx, param, value):
253252
"help": "Only process arguments, but don't execute actions.",
254253
"is_flag": True,
255254
"hidden": True,
256-
"default": False
255+
"default": False,
257256
},
258257
],
259258
"global_action_callbacks": [validate_root_options],
@@ -291,14 +290,15 @@ def list_targets_callback(ctx, param, value):
291290
"names": ["--style", "--color-scheme", "style"],
292291
"help": (
293292
"Menuconfig style.\n"
294-
"Is it possible to customize the menuconfig style by either setting the MENUCONFIG_STYLE "
295-
"environment variable or through this option. The built-in styles include:\n\n"
293+
"The built-in styles include:\n\n"
296294
"- default - a yellowish theme,\n\n"
297-
"- monochrome - a black and white theme, or\n"
295+
"- monochrome - a black and white theme, or\n\n"
298296
"- aquatic - a blue theme.\n\n"
299-
"The default value is \"aquatic\". It is possible to customize these themes further "
300-
"as it is described in the Color schemes section of the kconfiglib documentation."),
301-
"default": os.environ.get('MENUCONFIG_STYLE', 'aquatic'),
297+
"It is possible to customize these themes further"
298+
" as it is described in the Color schemes section of the kconfiglib documentation.\n"
299+
'The default value is \"aquatic\".'),
300+
"envvar": "MENUCONFIG_STYLE",
301+
"default": "aquatic",
302302
}
303303
],
304304
},

tools/idf_py_actions/serial_ext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ def global_callback(ctx, global_args, tasks):
134134

135135
baud_rate = {
136136
"names": ["-b", "--baud"],
137-
"help": "Baud rate for flashing. The default value can be set with the ESPBAUD environment variable.",
137+
"help": "Baud rate for flashing.",
138138
"scope": "global",
139139
"envvar": "ESPBAUD",
140140
"default": 460800,
141141
}
142142

143143
port = {
144144
"names": ["-p", "--port"],
145-
"help": "Serial port. The default value can be set with the ESPPORT environment variable.",
145+
"help": "Serial port.",
146146
"scope": "global",
147147
"envvar": "ESPPORT",
148148
"default": None,

0 commit comments

Comments
 (0)