|
32 | 32 | COMPLETER_FUNC_PREFIX = 'complete_' |
33 | 33 |
|
34 | 34 | # Prefix for private attributes injected by cmd2 |
35 | | -CMD2_ATTR_PREFIX = '_cmd2_' |
| 35 | +PRIVATE_ATTR_PREFIX = '_cmd2_' |
36 | 36 |
|
| 37 | +# Prefix for public attributes injected by cmd2 |
| 38 | +PUBLIC_ATTR_PREFIX = 'cmd2_' |
37 | 39 |
|
38 | | -def cmd2_attr_name(name: str) -> str: |
39 | | - """Build an attribute name with the cmd2 prefix. |
| 40 | + |
| 41 | +def cmd2_private_attr_name(name: str) -> str: |
| 42 | + """Build a private attribute name with the _cmd2_ prefix. |
40 | 43 |
|
41 | 44 | :param name: the name of the attribute |
42 | 45 | :return: the prefixed attribute name |
43 | 46 | """ |
44 | | - return f'{CMD2_ATTR_PREFIX}{name}' |
| 47 | + return f'{PRIVATE_ATTR_PREFIX}{name}' |
| 48 | + |
45 | 49 |
|
| 50 | +def cmd2_public_attr_name(name: str) -> str: |
| 51 | + """Build a public attribute name with the cmd2_ prefix. |
46 | 52 |
|
47 | | -# The custom help category a command belongs to |
48 | | -CMD_ATTR_HELP_CATEGORY = cmd2_attr_name('help_category') |
49 | | -CLASS_ATTR_DEFAULT_HELP_CATEGORY = cmd2_attr_name('default_help_category') |
| 53 | + :param name: the name of the attribute |
| 54 | + :return: the prefixed attribute name |
| 55 | + """ |
| 56 | + return f'{PUBLIC_ATTR_PREFIX}{name}' |
50 | 57 |
|
51 | | -# The argparse parser for the command |
52 | | -CMD_ATTR_ARGPARSER = cmd2_attr_name('argparser') |
| 58 | + |
| 59 | +################################################################################################## |
| 60 | +# Private cmd2-specific attributes for internal use |
| 61 | +################################################################################################## |
| 62 | +CMD_ATTR_HELP_CATEGORY = cmd2_private_attr_name('help_category') |
| 63 | +CLASS_ATTR_DEFAULT_HELP_CATEGORY = cmd2_private_attr_name('default_help_category') |
| 64 | + |
| 65 | +# The parser for a command |
| 66 | +CMD_ATTR_ARGPARSER = cmd2_private_attr_name('argparser') |
53 | 67 |
|
54 | 68 | # Whether or not tokens are unquoted before sending to argparse |
55 | | -CMD_ATTR_PRESERVE_QUOTES = cmd2_attr_name('preserve_quotes') |
| 69 | +CMD_ATTR_PRESERVE_QUOTES = cmd2_private_attr_name('preserve_quotes') |
| 70 | + |
| 71 | +# Subcommand attributes for the base command name and the subcommand name |
| 72 | +SUBCMD_ATTR_COMMAND = cmd2_private_attr_name('parent_command') |
| 73 | +SUBCMD_ATTR_NAME = cmd2_private_attr_name('subcommand_name') |
| 74 | +SUBCMD_ATTR_ADD_PARSER_KWARGS = cmd2_private_attr_name('subcommand_add_parser_kwargs') |
| 75 | + |
| 76 | +# Attribute added to a parser which uniquely identifies its command set instance |
| 77 | +PARSER_ATTR_COMMANDSET_ID = cmd2_private_attr_name('command_set_id') |
56 | 78 |
|
57 | | -# subcommand attributes for the base command name and the subcommand name |
58 | | -SUBCMD_ATTR_COMMAND = cmd2_attr_name('parent_command') |
59 | | -SUBCMD_ATTR_NAME = cmd2_attr_name('subcommand_name') |
60 | | -SUBCMD_ATTR_ADD_PARSER_KWARGS = cmd2_attr_name('subcommand_add_parser_kwargs') |
| 79 | +################################################################################################## |
| 80 | +# Public cmd2-specific attributes for use by developers |
| 81 | +################################################################################################## |
61 | 82 |
|
62 | | -# argparse attribute uniquely identifying the command set instance |
63 | | -PARSER_ATTR_COMMANDSET_ID = cmd2_attr_name('command_set_id') |
| 83 | +# Namespace attribute: Statement object that was created when parsing the command line |
| 84 | +NS_ATTR_STATEMENT = cmd2_public_attr_name('statement') |
64 | 85 |
|
65 | | -# custom attributes added to argparse Namespaces |
66 | | -NS_ATTR_SUBCMD_HANDLER = cmd2_attr_name('subcmd_handler') |
| 86 | +# Namespace attribute: subcommand handler function or None if one was not set |
| 87 | +NS_ATTR_SUBCMD_HANDLER = cmd2_public_attr_name('subcmd_handler') |
0 commit comments