|
31 | 31 | # All command completer functions start with this |
32 | 32 | COMPLETER_FUNC_PREFIX = 'complete_' |
33 | 33 |
|
| 34 | +# Prefix for private attributes injected by cmd2 |
| 35 | +CMD2_ATTR_PREFIX = '_cmd2_' |
| 36 | + |
| 37 | + |
| 38 | +def cmd2_attr_name(name: str) -> str: |
| 39 | + """Build an attribute name with the cmd2 prefix. |
| 40 | +
|
| 41 | + :param name: the name of the attribute |
| 42 | + :return: the prefixed attribute name |
| 43 | + """ |
| 44 | + return f'{CMD2_ATTR_PREFIX}{name}' |
| 45 | + |
| 46 | + |
34 | 47 | # The custom help category a command belongs to |
35 | | -CMD_ATTR_HELP_CATEGORY = 'help_category' |
36 | | -CLASS_ATTR_DEFAULT_HELP_CATEGORY = 'cmd2_default_help_category' |
| 48 | +CMD_ATTR_HELP_CATEGORY = cmd2_attr_name('help_category') |
| 49 | +CLASS_ATTR_DEFAULT_HELP_CATEGORY = cmd2_attr_name('default_help_category') |
37 | 50 |
|
38 | 51 | # The argparse parser for the command |
39 | | -CMD_ATTR_ARGPARSER = 'argparser' |
| 52 | +CMD_ATTR_ARGPARSER = cmd2_attr_name('argparser') |
40 | 53 |
|
41 | 54 | # Whether or not tokens are unquoted before sending to argparse |
42 | | -CMD_ATTR_PRESERVE_QUOTES = 'preserve_quotes' |
| 55 | +CMD_ATTR_PRESERVE_QUOTES = cmd2_attr_name('preserve_quotes') |
43 | 56 |
|
44 | 57 | # subcommand attributes for the base command name and the subcommand name |
45 | | -SUBCMD_ATTR_COMMAND = 'parent_command' |
46 | | -SUBCMD_ATTR_NAME = 'subcommand_name' |
47 | | -SUBCMD_ATTR_ADD_PARSER_KWARGS = 'subcommand_add_parser_kwargs' |
| 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') |
48 | 61 |
|
49 | | -# arpparse attribute uniquely identifying the command set instance |
50 | | -PARSER_ATTR_COMMANDSET_ID = 'command_set_id' |
| 62 | +# argparse attribute uniquely identifying the command set instance |
| 63 | +PARSER_ATTR_COMMANDSET_ID = cmd2_attr_name('command_set_id') |
51 | 64 |
|
52 | 65 | # custom attributes added to argparse Namespaces |
53 | | -NS_ATTR_SUBCMD_HANDLER = '__subcmd_handler__' |
| 66 | +NS_ATTR_SUBCMD_HANDLER = cmd2_attr_name('subcmd_handler') |
0 commit comments