Skip to content

Commit 0d22fc9

Browse files
committed
Updated documentation for the Settable class.
1 parent bc7fa0c commit 0d22fc9

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

cmd2/utils.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,32 @@ def __init__(
8383
) -> None:
8484
"""Settable Initializer.
8585
86-
:param name: name of the instance attribute being made settable
87-
:param val_type: callable used to cast the string value from the command line into its proper type and
88-
even validate its value. Setting this to bool provides tab completion for true/false and
89-
validation using to_bool(). The val_type function should raise an exception if it fails.
90-
This exception will be caught and printed by Cmd.do_set().
91-
:param description: string describing this setting
92-
:param settable_object: object to which the instance attribute belongs (e.g. self)
93-
:param settable_attrib_name: name which displays to the user in the output of the set command.
94-
Defaults to `name` if not specified.
95-
:param onchange_cb: optional function or method to call when the value of this settable is altered
96-
by the set command. (e.g. onchange_cb=self.debug_changed)
97-
98-
Cmd.do_set() passes the following 3 arguments to onchange_cb:
99-
param_name: str - name of the changed parameter
100-
old_value: Any - the value before being changed
101-
new_value: Any - the value after being changed
102-
103-
The following optional settings provide tab completion for a parameter's values. They correspond to the
104-
same settings in argparse-based tab completion. A maximum of one of these should be provided.
86+
:param name: The user-facing name for this setting in the CLI.
87+
:param val_type: A callable used to cast the string value from the CLI into its
88+
proper type and validate it. This function should raise an
89+
exception (like ValueError or TypeError) if the conversion or
90+
validation fails, which will be caught and displayed to the user
91+
by the set command. For example, setting this to int ensures the
92+
input is a valid integer. Specifying bool automatically provides
93+
tab completion for 'true' and 'false' and uses a built-in function
94+
for conversion and validation.
95+
:param description: A concise string that describes the purpose of this setting.
96+
:param settable_object: The object that owns the attribute being made settable (e.g. self).
97+
:param settable_attrib_name: The name of the attribute on the settable_object that
98+
will be modified. This defaults to the value of the name
99+
parameter if not specified.
100+
:param onchange_cb: An optional function or method to call when the value of this
101+
setting is altered by the set command. The callback is invoked
102+
only if the new value is different from the old one.
103+
104+
It receives three arguments:
105+
param_name: str - name of the parameter
106+
old_value: Any - the parameter's old value
107+
new_value: Any - the parameter's new value
108+
109+
The following optional settings provide tab completion for a parameter's values.
110+
They correspond to the same settings in argparse-based tab completion. A maximum
111+
of one of these should be provided.
105112
106113
:param choices: iterable of accepted values
107114
:param choices_provider: function that provides choices for this argument

0 commit comments

Comments
 (0)