Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
akhil-vempali committed Aug 21, 2024
1 parent e16088a commit e65efc3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ def make_context(

ctx = self.context_class(self, info_name=info_name, parent=parent, **extra)

with ctx.scope(cleanup=False):
with ctx:
self.parse_args(ctx, args)
return ctx

Expand Down
61 changes: 30 additions & 31 deletions src/click/shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,44 +544,43 @@ def _resolve_context(
:param args: List of complete args before the incomplete value.
"""
ctx_args["resilient_parsing"] = True
ctx = cli.make_context(prog_name, args.copy(), **ctx_args)
args = ctx._protected_args + ctx.args
with cli.make_context(prog_name, args.copy(), **ctx_args) as ctx:
args = ctx._protected_args + ctx.args

while args:
command = ctx.command
while args:
command = ctx.command

if isinstance(command, Group):
if not command.chain:
name, cmd, args = command.resolve_command(ctx, args)

if cmd is None:
return ctx

ctx = cmd.make_context(name, args, parent=ctx, resilient_parsing=True)
args = ctx._protected_args + ctx.args
else:
sub_ctx = ctx

while args:
if isinstance(command, Group):
if not command.chain:
name, cmd, args = command.resolve_command(ctx, args)

if cmd is None:
return ctx

sub_ctx = cmd.make_context(
name,
args,
parent=ctx,
allow_extra_args=True,
allow_interspersed_args=False,
resilient_parsing=True,
)
args = sub_ctx.args

ctx = sub_ctx
args = [*sub_ctx._protected_args, *sub_ctx.args]
else:
break
with cmd.make_context(name, args, parent=ctx, resilient_parsing=True) as sub_ctx:
args = sub_ctx._protected_args + sub_ctx.args
ctx = sub_ctx
else:
sub_ctx = ctx

while args:
name, cmd, args = command.resolve_command(ctx, args)

if cmd is None:
return ctx

with cmd.make_context(
name,
args,
parent=ctx,
allow_extra_args=True,
allow_interspersed_args=False,
resilient_parsing=True,
) as sub_ctx:
args = sub_ctx.args
ctx = sub_ctx
else:
break

return ctx

Expand Down

0 comments on commit e65efc3

Please sign in to comment.