diff --git a/tests/test_others.py b/tests/test_others.py index 1078e63d1f..0457c262d8 100644 --- a/tests/test_others.py +++ b/tests/test_others.py @@ -176,7 +176,7 @@ def test_completion_untyped_parameters(): }, ) assert "info name is: completion_no_types.py" in result.stderr - assert "args is: []" in result.stderr + assert "args is: ['--name', 'Sebastian', '--name']" in result.stderr assert "incomplete is: Ca" in result.stderr assert '"Camila":"The reader of books."' in result.stdout assert '"Carlos":"The writer of scripts."' in result.stdout @@ -202,7 +202,7 @@ def test_completion_untyped_parameters_different_order_correct_names(): }, ) assert "info name is: completion_no_types_order.py" in result.stderr - assert "args is: []" in result.stderr + assert "args is: ['--name', 'Sebastian', '--name']" in result.stderr assert "incomplete is: Ca" in result.stderr assert '"Camila":"The reader of books."' in result.stdout assert '"Carlos":"The writer of scripts."' in result.stdout diff --git a/tests/test_tutorial/test_options_autocompletion/test_tutorial008.py b/tests/test_tutorial/test_options_autocompletion/test_tutorial008.py index 0874f23c5d..67ea4256b1 100644 --- a/tests/test_tutorial/test_options_autocompletion/test_tutorial008.py +++ b/tests/test_tutorial/test_options_autocompletion/test_tutorial008.py @@ -23,7 +23,7 @@ def test_completion(): assert '"Camila":"The reader of books."' in result.stdout assert '"Carlos":"The writer of scripts."' in result.stdout assert '"Sebastian":"The type hints guy."' in result.stdout - assert "[]" in result.stderr + assert "['--name']" in result.stderr def test_1(): diff --git a/tests/test_tutorial/test_options_autocompletion/test_tutorial008_an.py b/tests/test_tutorial/test_options_autocompletion/test_tutorial008_an.py index cb2481a67c..59f9ed46ae 100644 --- a/tests/test_tutorial/test_options_autocompletion/test_tutorial008_an.py +++ b/tests/test_tutorial/test_options_autocompletion/test_tutorial008_an.py @@ -23,7 +23,7 @@ def test_completion(): assert '"Camila":"The reader of books."' in result.stdout assert '"Carlos":"The writer of scripts."' in result.stdout assert '"Sebastian":"The type hints guy."' in result.stdout - assert "[]" in result.stderr + assert "['--name']" in result.stderr def test_1(): diff --git a/tests/test_tutorial/test_options_autocompletion/test_tutorial009.py b/tests/test_tutorial/test_options_autocompletion/test_tutorial009.py index 3c7eb0cc64..d6888b3505 100644 --- a/tests/test_tutorial/test_options_autocompletion/test_tutorial009.py +++ b/tests/test_tutorial/test_options_autocompletion/test_tutorial009.py @@ -23,7 +23,7 @@ def test_completion(): assert '"Camila":"The reader of books."' in result.stdout assert '"Carlos":"The writer of scripts."' in result.stdout assert '"Sebastian":"The type hints guy."' not in result.stdout - assert "[]" in result.stderr + assert "['--name', 'Sebastian', '--name']" in result.stderr def test_1(): diff --git a/tests/test_tutorial/test_options_autocompletion/test_tutorial009_an.py b/tests/test_tutorial/test_options_autocompletion/test_tutorial009_an.py index 56182ac3b9..5a6e2fad06 100644 --- a/tests/test_tutorial/test_options_autocompletion/test_tutorial009_an.py +++ b/tests/test_tutorial/test_options_autocompletion/test_tutorial009_an.py @@ -23,7 +23,7 @@ def test_completion(): assert '"Camila":"The reader of books."' in result.stdout assert '"Carlos":"The writer of scripts."' in result.stdout assert '"Sebastian":"The type hints guy."' not in result.stdout - assert "[]" in result.stderr + assert "['--name', 'Sebastian', '--name']" in result.stderr def test_1(): diff --git a/typer/_completion_classes.py b/typer/_completion_classes.py index 070bbaa214..ac3d56a124 100644 --- a/typer/_completion_classes.py +++ b/typer/_completion_classes.py @@ -52,6 +52,10 @@ def get_completion_args(self) -> Tuple[List[str], str]: except IndexError: incomplete = "" + obj = self.ctx_args.setdefault("obj", {}) + if isinstance(obj, dict): + obj.setdefault("args", args) + return args, incomplete def format_completion(self, item: click.shell_completion.CompletionItem) -> str: @@ -87,6 +91,11 @@ def get_completion_args(self) -> Tuple[List[str], str]: args = args[:-1] else: incomplete = "" + + obj = self.ctx_args.setdefault("obj", {}) + if isinstance(obj, dict): + obj.setdefault("args", args) + return args, incomplete def format_completion(self, item: click.shell_completion.CompletionItem) -> str: @@ -138,6 +147,11 @@ def get_completion_args(self) -> Tuple[List[str], str]: args = args[:-1] else: incomplete = "" + + obj = self.ctx_args.setdefault("obj", {}) + if isinstance(obj, dict): + obj.setdefault("args", args) + return args, incomplete def format_completion(self, item: click.shell_completion.CompletionItem) -> str: @@ -187,6 +201,9 @@ def get_completion_args(self) -> Tuple[List[str], str]: incomplete = os.getenv("_TYPER_COMPLETE_WORD_TO_COMPLETE", "") cwords = click.parser.split_arg_string(completion_args) args = cwords[1:-1] if incomplete else cwords[1:] + obj = self.ctx_args.setdefault("obj", {}) + if isinstance(obj, dict): + obj.setdefault("args", args) return args, incomplete def format_completion(self, item: click.shell_completion.CompletionItem) -> str: diff --git a/typer/main.py b/typer/main.py index e552f6335f..cfff9859be 100644 --- a/typer/main.py +++ b/typer/main.py @@ -1058,7 +1058,8 @@ def wrapper(ctx: click.Context, args: List[str], incomplete: Optional[str]) -> A if ctx_name: use_params[ctx_name] = ctx if args_name: - use_params[args_name] = args + obj = ctx.obj or {} + use_params[args_name] = obj.get("args", []) if isinstance(obj, dict) else [] if incomplete_name: use_params[incomplete_name] = incomplete return callback(**use_params)