diff options
author | kotfu <kotfu@kotfu.net> | 2020-02-22 20:14:29 -0700 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2020-02-22 20:14:29 -0700 |
commit | 94e6309c0339a8460f9e97b097328ec6a7baac31 (patch) | |
tree | 8da69501939f11f169b83f122557d852f45aa68c /docs/examples | |
parent | bd95a11998f338dda53ed79fef46e2801b89f47e (diff) | |
download | cmd2-git-94e6309c0339a8460f9e97b097328ec6a7baac31.tar.gz |
Add links to recently added API documentation
Diffstat (limited to 'docs/examples')
-rw-r--r-- | docs/examples/first_app.rst | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/docs/examples/first_app.rst b/docs/examples/first_app.rst index 310c8d0c..85f84e31 100644 --- a/docs/examples/first_app.rst +++ b/docs/examples/first_app.rst @@ -40,15 +40,16 @@ First we need to create a new ``cmd2`` application. Create a new file sys.exit(c.cmdloop()) We have a new class ``FirstApp`` which is a subclass of -:ref:`api/cmd:cmd2.Cmd`. When we tell python to run our file like this: +:class:`cmd2.Cmd`. When we tell python to run our file like this: .. code-block:: shell $ python first_app.py -it creates an instance of our class, and calls the ``cmdloop()`` method. This -method accepts user input and runs commands based on that input. Because we -subclassed ``cmd2.Cmd``, our new app already has a bunch of features built in. +it creates an instance of our class, and calls the :meth:`~cmd2.Cmd.cmdloop` +method. This method accepts user input and runs commands based on that input. +Because we subclassed :class:`cmd2.Cmd`, our new app already has a bunch of +features built in. Congratulations, you have a working ``cmd2`` app. You can run it, and then type ``quit`` to exit. @@ -70,11 +71,10 @@ initializer to our class:: self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command')) In that initializer, the first thing to do is to make sure we initialize -``cmd2``. That's what the ``super().__init__()`` line does. Then we create an -attribute to hold our setting, and then add a description of our setting to the -``settable`` dictionary. If our attribute name isn't in ``settable``, then it -won't be treated as a setting. Now if you run the script, and enter the ``set`` -command to see the settings, like this: +``cmd2``. That's what the ``super().__init__()`` line does. Next create an +attribute to hold the setting. Finally, call the :meth:`~cmd2.Cmd.add_settable` +method with a new instance of a :meth:`~cmd2.utils.Settable` class. Now if you +run the script, and enter the ``set`` command to see the settings, like this: .. code-block:: shell @@ -131,8 +131,8 @@ There is also a new method called ``do_speak()``. In both cmd_ and ``cmd2``, methods that start with ``do_`` become new commands, so by defining this method we have created a command called ``speak``. -Note the ``@cmd2.with_argparser`` decorator on the ``do_speak()`` method. This -decorator does 3 useful things for us: +Note the :func:`~cmd2.decorators.with_argparser` decorator on the +``do_speak()`` method. This decorator does 3 useful things for us: 1. It tells ``cmd2`` to process all input for the ``speak`` command using the argparser we defined. If the user input doesn't meet the requirements @@ -159,8 +159,9 @@ benefits: 2. Gracefully handles ``BrokenPipeWarning`` exceptions for redirected output 3. Makes the output show up in a :ref:`transcript <features/transcripts:Transcripts>` -4. Honors the setting to strip embedded ansi sequences (typically used for - background and foreground colors) +4. Honors the setting to :ref:`strip embedded ansi sequences + <features/settings:allow_style>` (typically used for background and + foreground colors) Go run the script again, and try out the ``speak`` command. Try typing ``help speak``, and you will see a lovely usage message describing the various options |