Skip to content

Commit 788272e

Browse files
committed
Updated comments and example code.
1 parent 255c942 commit 788272e

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

cmd2/completion.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ class CompletionItem:
4949
# control sequences (like ^J or ^I) in the completion menu.
5050
_CONTROL_WHITESPACE_RE = re.compile(r"\r\n|[\n\r\t\f\v]")
5151

52-
# The underlying object this completion represents (e.g., str, int, Path).
53-
# This serves as the default source for 'text' and is used to support
54-
# object-based validation when this item is used as an argparse choice.
52+
# The source input for the completion. This is used to initialize the 'text'
53+
# field (defaults to str(value)). The original object is also preserved to
54+
# support object-based validation when this CompletionItem is used as an
55+
# argparse choice.
5556
value: Any = field(kw_only=False)
5657

57-
# The actual completion string. Defaults to str(value). This should only be
58-
# set manually if this item is used as an argparse choice and you want the
59-
# choice string to differ from str(value).
58+
# The string matched against user input and inserted into the command line.
59+
# Defaults to str(value). This should only be set manually if this
60+
# CompletionItem is used as an argparse choice and you want the choice
61+
# string to differ from str(value).
6062
text: str = _UNSET_STR
6163

6264
# Optional string for displaying the completion differently in the completion menu.

examples/completion_item_choices.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424

2525
import argparse
2626
import sys
27-
from typing import cast
27+
from typing import (
28+
ClassVar,
29+
cast,
30+
)
2831

2932
from cmd2 import (
3033
Cmd,
@@ -96,6 +99,8 @@ def account_lookup(name: str) -> Account:
9699
class ChoicesDemo(Cmd):
97100
"""Demo cmd2 application."""
98101

102+
DEFAULT_CATEGORY: ClassVar[str] = "Demo Commands"
103+
99104
def __init__(self) -> None:
100105
super().__init__()
101106
self.intro = (

0 commit comments

Comments
 (0)