Skip to content

Commit cc5a791

Browse files
authored
Documentation review (#1511)
Made a thorough read through our existing documentation and attempted to improve it. The kinds of things I was looking for include: -Try to fix anything which is outdated, incorrect, or inaccurate -Fix any place there was a TODO in the documentation by adding the missing documentation -Add links to the auto-generated API documentation for classes, methods, and functions where it makes sense -Improve wording anywhere it was lacking in clarity -Add links to relevant examples where it makes sense -Replace cut-and-paste help command output with updated versions that look slightly different
1 parent e3e0d6f commit cc5a791

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+916
-640
lines changed

docs/api/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
These pages document the public API for `cmd2`. If a method, class, function, attribute, or constant
44
is not documented here, consider it private and subject to change. There are many classes, methods,
5-
functions, and constants in the source code which do not begin with an underscore but are not
5+
functions, and constants in the source code that do not begin with an underscore but are not
66
documented here. When looking at the source code for this library, you cannot safely assume that
7-
because something doesn't start with an underscore, it is a public API.
7+
something is a public API just because it doesn't start with an underscore.
88

99
If a release of this library changes any of the items documented here, the version number will be
1010
incremented according to the [Semantic Version Specification](https://semver.org).
@@ -18,7 +18,7 @@ incremented according to the [Semantic Version Specification](https://semver.org
1818
- [cmd2.colors](./colors.md) - StrEnum of all color names supported by the Rich library
1919
- [cmd2.command_definition](./command_definition.md) - supports the definition of commands in
2020
separate classes to be composed into cmd2.Cmd
21-
- [cmd2.constants](./constants.md) - just like it says on the tin
21+
- [cmd2.constants](./constants.md) - constants used in `cmd2`
2222
- [cmd2.decorators](./decorators.md) - decorators for `cmd2` commands
2323
- [cmd2.exceptions](./exceptions.md) - custom `cmd2` exceptions
2424
- [cmd2.history](./history.md) - classes for storing the history of previously entered commands

docs/doc_conventions.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ In Markdown all indenting is significant. Use 4 spaces per indenting level.
3636

3737
## Wrapping
3838

39-
Hard wrap all text so that line lengths are no greater than 120 characters. It makes everything
39+
Hard wrap all text so that line lengths are no greater than 100 characters. It makes everything
4040
easier when editing documentation, and has no impact on reading documentation because we render to
4141
html.
4242

@@ -75,9 +75,13 @@ When using `mkdocstrings`, it must be preceded by a blank line before and after,
7575

7676
### Links to API Reference
7777

78-
To reference a method or function, do the following:
78+
To reference a class, method, or function, use block quotes around the name of the full namespace
79+
path for it followed by empty block quotes. So to reference `cmd2.Cmd`, you use `[cmd2.Cmd][]`.
7980

80-
TODO: Figure out how to do this
81+
If you want to change the name to use something shorter than the full namespace resolution you can
82+
put the full path in the 2nd set of block quotes instead of leaving it empty and put the shorter
83+
name in the one on the left. So you could also use `[Cmd][cmd2.Cmd]` to link to the API
84+
documentation for `cmd2.Cmd`.
8185

8286
## Referencing cmd2
8387

docs/examples/alternate_event_loops.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Alternate Event Loops
22

3-
Throughout this documentation we have focused on the **90%** use case, that is the use case we
4-
believe around **90+%** of our user base is looking for. This focuses on ease of use and the best
5-
out-of-the-box experience where developers get the most functionality for the least amount of
6-
effort. We are talking about running `cmd2` applications with the `cmdloop()` method:
3+
Throughout this documentation, we have focused on the 90% use case, which we believe applies to over
4+
90% of our user base. This focuses on ease of use and the best out-of-the-box experience, where
5+
developers get the most functionality for the least amount of effort. We are talking about running
6+
`cmd2` applications with the `cmdloop()` method:
77

88
```py
99
from cmd2 import Cmd
@@ -21,8 +21,8 @@ Many Python concurrency libraries involve or require an event loop which they ar
2121
such as [asyncio](https://docs.python.org/3/library/asyncio.html), [gevent](http://www.gevent.org/),
2222
[Twisted](https://twistedmatrix.com), etc.
2323

24-
`cmd2` applications can be executed in a fashion where `cmd2` doesn't own the main loop for the
25-
program by using code like the following:
24+
`cmd2` applications can be executed in a way where `cmd2` doesn't own the main loop for the program
25+
by using code like the following:
2626

2727
```py
2828
import cmd2
@@ -44,29 +44,29 @@ if __name__ == '__main__':
4444
app.postloop()
4545
```
4646

47-
The `cmd2.Cmd.runcmds_plus_hooks()` method runs multiple commands via
48-
`cmd2.Cmd.onecmd_plus_hooks()`.
47+
The [cmd2.Cmd.runcmds_plus_hooks][] method runs multiple commands where each single command is
48+
executed via [cmd2.Cmd.onecmd_plus_hooks][].
4949

50-
The `cmd2.Cmd.onecmd_plus_hooks()` method will do the following to execute a single command in a
50+
The [cmd2.Cmd.onecmd_plus_hooks][] method will do the following to execute a single command in a
5151
normal fashion:
5252

53-
1. Parse user input into a `cmd2.Statement` object
54-
1. Call methods registered with `cmd2.Cmd.register_postparsing_hook()`
53+
1. Parse user input into a [cmd2.Statement][] object
54+
1. Call methods registered with [cmd2.Cmd.register_postparsing_hook][]
5555
1. Redirect output, if user asked for it and it's allowed
5656
1. Start timer
57-
1. Call methods registered with `cmd2.Cmd.register_precmd_hook`
58-
1. Call `cmd2.Cmd.precmd` - for backwards compatibility with `cmd.Cmd`
57+
1. Call methods registered with [cmd2.Cmd.register_precmd_hook][]
58+
1. Call [cmd2.Cmd.precmd][] - for backwards compatibility with `cmd`
5959
1. Add statement to [History](../features/history.md)
6060
1. Call `do_command` method
61-
1. Call methods registered with `cmd2.Cmd.register_postcmd_hook()`
62-
1. Call `cmd2.Cmd.postcmd` - for backwards compatibility with `cmd.Cmd`
61+
1. Call methods registered with [cmd2.Cmd.register_postcmd_hook][]
62+
1. Call [cmd2.Cmd.postcmd][] - for backwards compatibility with `cmd`
6363
1. Stop timer and display the elapsed time
6464
1. Stop redirecting output if it was redirected
65-
1. Call methods registered with `cmd2.Cmd.register_cmdfinalization_hook()`
65+
1. Call methods registered with [cmd2.Cmd.register_cmdfinalization_hook][]
6666

67-
Running in this fashion enables the ability to integrate with an external event loop. However, how
68-
to integrate with any specific event loop is beyond the scope of this documentation. Please note
69-
that running in this fashion comes with several disadvantages, including:
67+
Running in this way enables the ability to integrate with an external event loop. However, how to
68+
integrate with any specific event loop is beyond the scope of this documentation. Please note that
69+
running in this fashion comes with several disadvantages, including:
7070

7171
- Requires the developer to write more code
7272
- Does not support transcript testing

docs/examples/getting_started.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Getting Started
22

3-
Here's a quick walkthrough of a simple application which demonstrates 10 features of `cmd2`:
3+
Here's a quick walkthrough of the simple
4+
[getting_started.py](https://github.com/python-cmd2/cmd2/blob/main/examples/getting_started.py)
5+
example application which demonstrates many features of `cmd2`:
46

57
- [Settings](../features/settings.md)
68
- [Commands](../features/commands.md)
@@ -29,36 +31,36 @@ following contents:
2931

3032
```py
3133
#!/usr/bin/env python
32-
"""A simple cmd2 application."""
34+
"""A basic cmd2 application."""
3335
import cmd2
3436

3537

36-
class FirstApp(cmd2.Cmd):
37-
"""A simple cmd2 application."""
38+
class BasicApp(cmd2.Cmd):
39+
"""Cmd2 application to demonstrate many common features."""
3840

3941

4042
if __name__ == '__main__':
4143
import sys
42-
c = FirstApp()
43-
sys.exit(c.cmdloop())
44+
app = BasicApp()
45+
sys.exit(app.cmdloop())
4446
```
4547

46-
We have a new class `FirstApp` which is a subclass of [cmd2.Cmd][]. When we tell python to run our
48+
We have a new class `BasicApp` which is a subclass of [cmd2.Cmd][]. When we tell Python to run our
4749
file like this:
4850

4951
```shell
5052
$ python getting_started.py
5153
```
5254

53-
it creates an instance of our class, and calls the `cmd2.Cmd.cmdloop` method. This method accepts
54-
user input and runs commands based on that input. Because we subclassed `cmd2.Cmd`, our new app
55-
already has a bunch of features built in.
55+
The application creates an instance of our class, and calls the [cmd2.Cmd.cmdloop][] method. This
56+
method accepts user input and runs commands based on that input. Because we subclassed `cmd2.Cmd`,
57+
our new app already has a bunch of built-in features.
5658

5759
Congratulations, you have a working `cmd2` app. You can run it, and then type `quit` to exit.
5860

5961
## Create a New Setting
6062

61-
Before we create our first command, we are going to add a setting to this app. `cmd2` includes
63+
Before we create our first command, we are going to add a new setting to this app. `cmd2` includes
6264
robust support for [Settings](../features/settings.md). You configure settings during object
6365
initialization, so we need to add an initializer to our class:
6466

@@ -85,11 +87,11 @@ you will see our `maxrepeats` setting show up with its default value of `3`.
8587

8688
## Create A Command
8789

88-
Now we will create our first command, called `speak` which will echo back whatever we tell it to
90+
Now we will create our first command, called `speak`, which will echo back whatever we tell it to
8991
say. We are going to use an [argument processor](../features/argument_processing.md) so the `speak`
90-
command can shout and talk pig latin. We will also use some built in methods for
92+
command can shout and talk Pig Latin. We will also use some built in methods for
9193
[generating output](../features/generating_output.md). Add this code to `getting_started.py`, so
92-
that the `speak_parser` attribute and the `do_speak()` method are part of the `FirstApp()` class:
94+
that the `speak_parser` attribute and the `do_speak()` method are part of the `BasicApp()` class:
9395

9496
```py
9597
speak_parser = cmd2.Cmd2ArgumentParser()
@@ -122,7 +124,7 @@ import argparse
122124

123125
There's a bit to unpack here, so let's walk through it. We created `speak_parser`, which uses the
124126
[argparse](https://docs.python.org/3/library/argparse.html) module from the Python standard library
125-
to parse command line input from a user. There is nothing thus far that is specific to `cmd2`.
127+
to parse command line input from a user. So far, there is nothing specific to `cmd2`.
126128

127129
There is also a new method called `do_speak()`. In both
128130
[cmd](https://docs.python.org/3/library/cmd.html) and `cmd2`, methods that start with `do_` become
@@ -135,12 +137,12 @@ Note the `cmd2.decorators.with_argparser` decorator on the `do_speak()` method.
135137
the user input doesn't meet the requirements defined by the argparser, then an error will be
136138
displayed for the user.
137139
1. It alters our `do_speak` method so that instead of receiving the raw user input as a parameter,
138-
we receive the namespace from the argparser.
140+
we receive the namespace from the argument parser.
139141
1. It creates a help message for us based on the argparser.
140142

141143
You can see in the body of the method how we use the namespace from the argparser (passed in as the
142-
variable `args`). We build an array of words which we will output, honoring both the `--piglatin`
143-
and `--shout` options.
144+
variable `args`). We build a list of words which we will output, honoring both the `--piglatin` and
145+
`--shout` options.
144146

145147
At the end of the method, we use our `maxrepeats` setting as an upper limit to the number of times
146148
we will print the output.
@@ -196,9 +198,9 @@ def __init__(self):
196198

197199
Shortcuts are passed to the `cmd2` initializer, and if you want the built-in shortcuts of `cmd2` you
198200
have to pass them. These shortcuts are defined as a dictionary, with the key being the shortcut, and
199-
the value containing the command. When using the default shortcuts and also adding your own, it's a
200-
good idea to use the `.update()` method to modify the dictionary. This way if you add a shortcut
201-
that happens to already be in the default set, yours will override, and you won't get any errors at
201+
the value containing the command. When using the default shortcuts and adding your own, it's a good
202+
idea to use the `.update()` method to modify the dictionary. This way, if you add a shortcut that
203+
happens to already be in the default set, yours will override, and you won't get any errors at
202204
runtime.
203205

204206
Run your app again, and type:
@@ -207,16 +209,15 @@ Run your app again, and type:
207209
(Cmd) shortcuts
208210
```
209211

210-
to see the list of all of the shortcuts, including the one for speak that we just created.
212+
to see the list of all the shortcuts, including the one for speak that we just created.
211213

212214
## Multiline Commands
213215

214-
Some use cases benefit from the ability to have commands that span more than one line. For example,
215-
you might want the ability for your user to type in a SQL command, which can often span lines and
216-
which are terminated with a semicolon. Let's add a
217-
[multiline command](../features/multiline_commands.md) to our application. First we'll create a new
218-
command called `orate`. This code shows both the definition of our `speak` command, and the `orate`
219-
command:
216+
Some use cases benefit from commands that span more than one line. For example, you might want the
217+
ability for your user to type in a SQL command, which can often span lines and which are terminated
218+
with a semicolon. Let's add a [multiline command](../features/multiline_commands.md) to our
219+
application. First we'll create a new command called `orate`. This code shows both the definition of
220+
our `speak` command, and the `orate` command:
220221

221222
```py
222223
@cmd2.with_argparser(speak_parser)

0 commit comments

Comments
 (0)