Using cmd to create command-line applications
There are several ways of creating interactive applications. The Using input() and getpass() for user input recipe looked at functions such as
getpass.getpass(). The Using argparse to get command-line input recipe showed us how to use
argparse to create applications with which a user can interact from the OS command line.
We have a third way to create interactive applications: using the
cmd module. This module will prompt the user for input, and then invoke a specific method of the class we provide.
Here's how the interaction will look – we've marked user input like this: "
A dice rolling tool. ? for help.
Documented commands (type help <topic>):
dice help reroll roll
] help roll
Roll the dice. Use the dice command to set the number of dice.
] help dice
Sets the number...