Skip to content

Commit af92cb2

Browse files
committed
only initialize the completion once
this way the first initializer is the one that sets the completion configuration
1 parent f377183 commit af92cb2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

click_completion/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,24 @@ def _shellcomplete(cli, prog_name, complete_var=None):
280280
sys.exit()
281281

282282

283+
_initialized = False
284+
285+
283286
def init(complete_options=False):
284287
"""Initialize the enhanced click completion
285288
286289
Args:
287290
complete_options (bool): always complete the options, even when the user hasn't typed a first dash
288291
"""
289-
import click
290-
click.types.ParamType.complete = param_type_complete
291-
click.types.Choice.complete = choice_complete
292-
click.core.MultiCommand.get_command_short_help = multicommand_get_command_short_help
293-
click.core._bashcomplete = _shellcomplete
294-
completion_configuration.complete_options = complete_options
292+
global _initialized
293+
if not _initialized:
294+
import click
295+
click.types.ParamType.complete = param_type_complete
296+
click.types.Choice.complete = choice_complete
297+
click.core.MultiCommand.get_command_short_help = multicommand_get_command_short_help
298+
click.core._bashcomplete = _shellcomplete
299+
completion_configuration.complete_options = complete_options
300+
_initialized = True
295301

296302

297303
class DocumentedChoice(ParamType):

0 commit comments

Comments
 (0)