Skip to content

Commit 9cb4e7d

Browse files
peterdragunradimkarnis
authored andcommitted
change: Fix autocomplete for espefuse
1 parent 4586e4b commit 9cb4e7d

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

espefuse/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"--port",
6363
"-p",
6464
envvar="ESPTOOL_PORT",
65+
type=click.Path(),
6566
help="Serial port device.",
6667
)
6768
@click.option(

espefuse/cli_util.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ def parse_args(self, ctx: click.Context, args: list[str]):
120120
# so we need to account for BLOCK2 being processed separately
121121
param.nargs = args.index(arg) - arguments_count + 1
122122
param_changed = param
123-
if param.nargs == 0 and param.required:
123+
if (
124+
param.nargs == 0
125+
and param.required
126+
and not ctx.resilient_parsing
127+
):
124128
raise click.UsageError(
125129
f"Command `{self.name}` requires the `{param.name}` "
126130
"argument."
@@ -211,7 +215,11 @@ def parse_args(self, ctx: click.Context, args: list[str]):
211215
args = self._replace_deprecated_args(args)
212216
cmd_groups, used_cmds = self._split_to_groups(args)
213217

214-
if len(used_cmds) == 0:
218+
# Add commands for shell completion
219+
if ctx.resilient_parsing:
220+
commands = init_commands(port=None, chip=ctx.obj["chip"], skip_connect=True)
221+
commands.add_cli_commands(self)
222+
elif len(used_cmds) == 0:
215223
self.get_help(ctx)
216224
ctx.exit()
217225

esptool/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ def check_flash_size(esp: ESPLoader, address: int, size: int) -> None:
311311
@click.option(
312312
"--port",
313313
"-p",
314+
type=click.Path(),
314315
default=os.environ.get("ESPTOOL_PORT", None),
315316
help="Serial port device.",
316317
)

esptool/cli_util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,11 @@ def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None
265265

266266
def resolve_command(
267267
self, ctx: click.Context, args: list[str]
268-
) -> tuple[str, click.Command, list[str]]:
268+
) -> tuple[str | None, click.Command | None, list[str]]:
269269
# always return the full command name
270270
_, cmd, args = super().resolve_command(ctx, args)
271+
if cmd is None:
272+
return None, None, args
271273
return cmd.name, cmd, args
272274

273275

0 commit comments

Comments
 (0)