@@ -127,7 +127,7 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens) -> Completions
127127
1281281. display - string for displaying the completion differently in the completion menu
1291292. display_meta - meta information about completion which displays in the completion menu
130- 3. table_row - row data for completion tables
130+ 3. table_data - supplemental data for completion tables
131131
132132They can also be used as argparse choices. When a ``CompletionItem`` is created, it
133133stores the original value (e.g. ID number) and makes it accessible through a property
@@ -139,8 +139,8 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens) -> Completions
139139These were added to help in cases where uninformative data is being completed.
140140For instance, completing ID numbers isn't very helpful to a user without context.
141141
142- Providing ``table_row`` data in your ``CompletionItem`` signals ArgparseCompleter
143- to output the completion results in a table with descriptive data instead of just a table
142+ Providing ``table_data`` in your ``CompletionItem`` signals ArgparseCompleter
143+ to output the completion results in a table with supplemental data instead of just a table
144144of tokens::
145145
146146 Instead of this:
@@ -155,35 +155,34 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens) -> Completions
155155
156156
157157The left-most column is the actual value being completed and its header is
158- that value's name. The right column header is defined using the
159- ``table_header `` parameter of add_argument(), which is a list of header
160- names that defaults to ["Description"] . The right column values come from the
161- ``table_row `` argument to ``CompletionItem``. It's a ``Sequence`` with the
162- same number of items as ``table_header ``.
158+ that value's name. Any additional column headers are defined using the
159+ ``table_columns `` parameter of add_argument(), which is a list of header
160+ names. The supplemental column values come from the
161+ ``table_data `` argument to ``CompletionItem``. It's a ``Sequence`` with the
162+ same number of items as ``table_columns ``.
163163
164164Example::
165165
166- Add an argument and define its table_header .
166+ Add an argument and define its table_columns .
167167
168168 parser.add_argument(
169- add_argument(
170169 "item_id",
171170 type=int,
172171 choices_provider=get_choices,
173- table_header =["Item Name", "Checked Out", "Due Date"],
172+ table_columns =["Item Name", "Checked Out", "Due Date"],
174173 )
175174
176175 Implement the choices_provider to return Choices.
177176
178177 def get_choices(self) -> Choices:
179178 \" \" \" choices_provider which returns CompletionItems\" \" \"
180179
181- # Populate CompletionItem's table_row argument.
182- # Its item count should match that of table_header .
180+ # Populate CompletionItem's table_data argument.
181+ # Its item count should match that of table_columns .
183182 items = [
184- CompletionItem(1, table_row =["My item", True, "02/02/2022"]),
185- CompletionItem(2, table_row =["Another item", False, ""]),
186- CompletionItem(3, table_row =["Yet another item", False, ""]),
183+ CompletionItem(1, table_data =["My item", True, "02/02/2022"]),
184+ CompletionItem(2, table_data =["Another item", False, ""]),
185+ CompletionItem(3, table_data =["Yet another item", False, ""]),
187186 ]
188187 return Choices(items)
189188
@@ -195,7 +194,7 @@ def get_choices(self) -> Choices:
195194 2 Another item False
196195 3 Yet another item False
197196
198- ``table_header `` can be strings or ``Rich.table.Columns`` for more
197+ ``table_columns `` can be strings or ``Rich.table.Columns`` for more
199198control over things like alignment.
200199
201200- If a header is a string, it will render as a left-aligned column with its
@@ -207,9 +206,9 @@ def get_choices(self) -> Choices:
207206truncated with an ellipsis at the end. You can override this and other settings
208207when you create the ``Column``.
209208
210- ``table_row `` items can include Rich objects, including styled Text and Tables.
209+ ``table_data `` items can include Rich objects, including styled Text and Tables.
211210
212- To avoid printing a excessive information to the screen at once when a user
211+ To avoid printing excessive information to the screen at once when a user
213212presses tab, there is a maximum threshold for the number of ``CompletionItems``
214213that will be shown. Its value is defined in ``cmd2.Cmd.max_completion_table_items``.
215214It defaults to 50, but can be changed. If the number of completion suggestions
@@ -240,8 +239,8 @@ def get_choices(self) -> Choices:
240239- ``argparse.Action.get_choices_callable()`` - See `action_get_choices_callable` for more details.
241240- ``argparse.Action.set_choices_provider()`` - See `_action_set_choices_provider` for more details.
242241- ``argparse.Action.set_completer()`` - See `_action_set_completer` for more details.
243- - ``argparse.Action.get_table_header ()`` - See `_action_get_table_header ` for more details.
244- - ``argparse.Action.set_table_header ()`` - See `_action_set_table_header ` for more details.
242+ - ``argparse.Action.get_table_columns ()`` - See `_action_get_table_columns ` for more details.
243+ - ``argparse.Action.set_table_columns ()`` - See `_action_set_table_columns ` for more details.
245244- ``argparse.Action.get_nargs_range()`` - See `_action_get_nargs_range` for more details.
246245- ``argparse.Action.set_nargs_range()`` - See `_action_set_nargs_range` for more details.
247246- ``argparse.Action.get_suppress_tab_hint()`` - See `_action_get_suppress_tab_hint` for more details.
@@ -418,8 +417,8 @@ def completer(self) -> CompleterUnbound[CmdOrSet]:
418417# ChoicesCallable object that specifies the function to be called which provides choices to the argument
419418ATTR_CHOICES_CALLABLE = 'choices_callable'
420419
421- # A completion table header
422- ATTR_TABLE_HEADER = 'table_header '
420+ # Completion table columns
421+ ATTR_TABLE_COLUMNS = 'table_columns '
423422
424423# A tuple specifying nargs as a range (min, max)
425424ATTR_NARGS_RANGE = 'nargs_range'
@@ -516,38 +515,38 @@ def _action_set_completer(
516515
517516
518517############################################################################################################
519- # Patch argparse.Action with accessors for table_header attribute
518+ # Patch argparse.Action with accessors for table_columns attribute
520519############################################################################################################
521- def _action_get_table_header (self : argparse .Action ) -> Sequence [str | Column ] | None :
522- """Get the table_header attribute of an argparse Action.
520+ def _action_get_table_columns (self : argparse .Action ) -> Sequence [str | Column ] | None :
521+ """Get the table_columns attribute of an argparse Action.
523522
524- This function is added by cmd2 as a method called ``get_table_header ()`` to ``argparse.Action`` class.
523+ This function is added by cmd2 as a method called ``get_table_columns ()`` to ``argparse.Action`` class.
525524
526- To call: ``action.get_table_header ()``
525+ To call: ``action.get_table_columns ()``
527526
528527 :param self: argparse Action being queried
529- :return: The value of table_header or None if attribute does not exist
528+ :return: The value of table_columns or None if attribute does not exist
530529 """
531- return cast (Sequence [str | Column ] | None , getattr (self , ATTR_TABLE_HEADER , None ))
530+ return cast (Sequence [str | Column ] | None , getattr (self , ATTR_TABLE_COLUMNS , None ))
532531
533532
534- setattr (argparse .Action , 'get_table_header ' , _action_get_table_header )
533+ setattr (argparse .Action , 'get_table_columns ' , _action_get_table_columns )
535534
536535
537- def _action_set_table_header (self : argparse .Action , table_header : Sequence [str | Column ] | None ) -> None :
538- """Set the table_header attribute of an argparse Action.
536+ def _action_set_table_columns (self : argparse .Action , table_columns : Sequence [str | Column ] | None ) -> None :
537+ """Set the table_columns attribute of an argparse Action.
539538
540- This function is added by cmd2 as a method called ``set_table_header ()`` to ``argparse.Action`` class.
539+ This function is added by cmd2 as a method called ``set_table_columns ()`` to ``argparse.Action`` class.
541540
542- To call: ``action.set_table_header(table_header )``
541+ To call: ``action.set_table_columns(table_columns )``
543542
544543 :param self: argparse Action being updated
545- :param table_header : value being assigned
544+ :param table_columns : value being assigned
546545 """
547- setattr (self , ATTR_TABLE_HEADER , table_header )
546+ setattr (self , ATTR_TABLE_COLUMNS , table_columns )
548547
549548
550- setattr (argparse .Action , 'set_table_header ' , _action_set_table_header )
549+ setattr (argparse .Action , 'set_table_columns ' , _action_set_table_columns )
551550
552551
553552############################################################################################################
@@ -698,7 +697,7 @@ def _add_argument_wrapper(
698697 choices_provider : ChoicesProviderUnbound [CmdOrSet ] | None = None ,
699698 completer : CompleterUnbound [CmdOrSet ] | None = None ,
700699 suppress_tab_hint : bool = False ,
701- table_header : Sequence [str | Column ] | None = None ,
700+ table_columns : Sequence [str | Column ] | None = None ,
702701 ** kwargs : Any ,
703702) -> argparse .Action :
704703 """Wrap ActionsContainer.add_argument() which supports more settings used by cmd2.
@@ -718,7 +717,7 @@ def _add_argument_wrapper(
718717 current argument's help text as a hint. Set this to True to suppress the hint. If this
719718 argument's help text is set to argparse.SUPPRESS, then tab hints will not display
720719 regardless of the value passed for suppress_tab_hint. Defaults to False.
721- :param table_header : optional header for when displaying a completion table. Defaults to None.
720+ :param table_columns : optional headers for when displaying a completion table. Defaults to None.
722721
723722 # Args from original function
724723 :param kwargs: keyword-arguments recognized by argparse._ActionsContainer.add_argument
@@ -809,7 +808,7 @@ def _add_argument_wrapper(
809808 new_arg .set_completer (completer ) # type: ignore[attr-defined]
810809
811810 new_arg .set_suppress_tab_hint (suppress_tab_hint ) # type: ignore[attr-defined]
812- new_arg .set_table_header ( table_header ) # type: ignore[attr-defined]
811+ new_arg .set_table_columns ( table_columns ) # type: ignore[attr-defined]
813812
814813 for keyword , value in custom_attribs .items ():
815814 attr_setter = getattr (new_arg , f'set_{ keyword } ' , None )
0 commit comments