@@ -717,6 +717,16 @@ def print_help(self, tokens: Sequence[str], file: IO[str] | None = None) -> None
717717
718718 def _choices_to_items (self , arg_state : _ArgumentState ) -> list [CompletionItem ]:
719719 """Convert choices from action to list of CompletionItems."""
720+ action_type = arg_state .action .type
721+ if action_type is not None and arg_state .action .choices is None :
722+ if isinstance (action_type , type ) and issubclass (action_type , enum .Enum ):
723+ return [CompletionItem (str (m .value ), display_meta = m .name ) for m in action_type ]
724+ enum_from_converter = getattr (action_type , '_cmd2_enum_class' , None )
725+ if isinstance (enum_from_converter , type ) and issubclass (enum_from_converter , enum .Enum ):
726+ return [CompletionItem (str (m .value ), display_meta = m .name ) for m in enum_from_converter ]
727+ if getattr (action_type , '__name__' , None ) == '_parse_bool' :
728+ return [CompletionItem (v ) for v in ['true' , 'false' , 'yes' , 'no' , 'on' , 'off' , '1' , '0' ]]
729+
720730 if arg_state .action .choices is None :
721731 return []
722732
@@ -733,29 +743,6 @@ def _choices_to_items(self, arg_state: _ArgumentState) -> list[CompletionItem]:
733743 for name , subparser in arg_state .action .choices .items ()
734744 ]
735745
736- choices_callable : ChoicesCallable | None = arg_state .action .get_choices_callable () # type: ignore[attr-defined]
737- if choices_callable is not None :
738- return choices_callable
739-
740- # Type inference: auto-complete from action.type when no explicit
741- # choices or choices_callable is configured.
742- action_type = arg_state .action .type
743- if action_type is not None :
744- if action_type is pathlib .Path or (isinstance (action_type , type ) and issubclass (action_type , pathlib .Path )):
745- from .cmd2 import Cmd
746-
747- return ChoicesCallable (is_completer = True , to_call = Cmd .path_complete )
748-
749- if isinstance (action_type , type ) and issubclass (action_type , enum .Enum ):
750- return [CompletionItem (str (m .value ), display_meta = m .name ) for m in action_type ]
751-
752- enum_from_converter = getattr (action_type , '_cmd2_enum_class' , None )
753- if isinstance (enum_from_converter , type ) and issubclass (enum_from_converter , enum .Enum ):
754- return [CompletionItem (str (m .value ), display_meta = m .name ) for m in enum_from_converter ]
755-
756- if getattr (action_type , '__name__' , None ) == '_parse_bool' :
757- return [CompletionItem (v ) for v in ['true' , 'false' , 'yes' , 'no' , 'on' , 'off' , '1' , '0' ]]
758-
759746 # Standard choices
760747 return [
761748 choice if isinstance (choice , CompletionItem ) else CompletionItem (choice ) for choice in arg_state .action .choices
@@ -817,6 +804,13 @@ def _complete_arg(
817804 )
818805 args .extend ([text , line , begidx , endidx ])
819806 completions : Completions = completer (* args , ** kwargs )
807+ # if is a path type, then use cmd2's path completer
808+ elif arg_state .action .type is pathlib .Path or (
809+ isinstance (arg_state .action .type , type ) and issubclass (arg_state .action .type , pathlib .Path )
810+ ):
811+ from .cmd2 import Cmd
812+
813+ completions = Cmd .path_complete (self ._cmd2_app , text , line , begidx , endidx )
820814
821815 # Otherwise it uses a choices provider or choices list
822816 else :
0 commit comments