diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-08-25 16:11:49 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-08-26 17:52:34 -0400 |
commit | 478ea83336a4d1659ad06ef365db3dc5e051e46d (patch) | |
tree | cbaff855e2d73f1d86ae1230f32770e31c62ad6b /docs | |
parent | 97c348c599d8fa963553593e5c19fb100b85e313 (diff) | |
download | cmd2-git-478ea83336a4d1659ad06ef365db3dc5e051e46d.tar.gz |
The functions cmd2 adds to Namespaces (get_statement() and get_handler()) are now
Cmd2AttributeWrapper objects named cmd2_statement and cmd2_handler. This makes it
easy to filter out which attributes in an argparse.Namespace were added by cmd2.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/features/argument_processing.rst | 20 | ||||
-rw-r--r-- | docs/features/modular_commands.rst | 2 | ||||
-rw-r--r-- | docs/testing.rst | 2 |
3 files changed, 13 insertions, 11 deletions
diff --git a/docs/features/argument_processing.rst b/docs/features/argument_processing.rst index 7ce8c815..06f48f82 100644 --- a/docs/features/argument_processing.rst +++ b/docs/features/argument_processing.rst @@ -13,9 +13,8 @@ handles the following for you: 3. Passes the resulting ``argparse.Namespace`` object to your command function. The ``Namespace`` includes the ``Statement`` object that was created when - parsing the command line. It is stored in the ``__statement__`` attribute of - the ``Namespace`` and can also be retrieved by calling ``get_statement()`` - on the ``Namespace``. + parsing the command line. It can be retrieved by calling + ``cmd2_statement.get()`` on the ``Namespace``. 4. Adds the usage message from the argument parser to your command. @@ -391,10 +390,13 @@ Reserved Argument Names Namespaces. To avoid naming collisions, do not use any of the names for your argparse arguments. +- ``cmd2_statement`` - ``cmd2.Cmd2AttributeWrapper`` object containing + ``cmd2.Statement`` object that was created when parsing the command line. - ``__statement__`` - ``cmd2.Statement`` object that was created when parsing - the command line. -- ``get_statement()`` - convenience function which returns the ``Statement`` -- ``__subcmd_handler__`` - points to subcommand handler function. This is added - when using the ``@cmd2.as_subcommand_to`` decorator. -- ``get_handler()`` - convenience function which returns the subcommand handler - or ``None`` if one was not set + the command line. (This is deprecated and will be removed in 2.0.0.) Use + ``cmd2_statement`` instead. + +- ``__subcmd_handler__`` - used by cmd2 to identify the handler for a + subcommand created with ``@cmd2.as_subcommand_to`` decorator. +- ``cmd2_handler`` - ``cmd2.Cmd2AttributeWrapper`` object containing + a subcommand handler function or ``None`` if one was not set. diff --git a/docs/features/modular_commands.rst b/docs/features/modular_commands.rst index dddd996e..4abeda2d 100644 --- a/docs/features/modular_commands.rst +++ b/docs/features/modular_commands.rst @@ -316,7 +316,7 @@ command and each CommandSet @with_argparser(cut_parser) def do_cut(self, ns: argparse.Namespace): - handler = ns.get_handler() + handler = ns.cmd2_handler.get() if handler is not None: # Call whatever subcommand function was selected handler(ns) diff --git a/docs/testing.rst b/docs/testing.rst index 811e1137..43838c99 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -38,7 +38,7 @@ this, you should always mock with `Autospeccing <python_mock_autospeccing_>`_ or enabled. Example of spec=True -==================== +~~~~~~~~~~~~~~~~~~~~ .. code-block:: python def test_mocked_methods(): |