Putting Everything Together Now that you have a basic understanding of the required help screen elements, it’s time to look at an
example. Listing 10-5 shows a typical
usage()
function. It displays help information to users who
need it, using simple
print()
statements.
LISTINg 10-5: Creating a help screen for your application # Create a usage() function.
def usage():
print ‘Welcome to the command line example.’
print ‘This application shows basic command line argument reading.’
print ‘\nUsage:’
print ‘\tIPY CmdLine2.py [Options]‘
print ‘\nOptions:’
print ‘\t-D: Places application in debug mode.’
print ‘\t-h or -? or --help: Displays this help message.’
print ‘\t-g: or --Greet:: Displays a simple greeting.’
print ‘\t-s or --Hello: Displays a simple hello message.’
print ‘\nExamples:’
print ‘\tIPY CmdLine2.py -s outputs Hello!’
print ‘\tIPY CmdLine2.py -g:John outputs Good to see you John’
print ‘\tYou can use either the - or / as command line switches.’
print ‘\tFor example, IPY CmdLine2.py /s outputs Hello!’
Notice the use of formatting in the code. The code places section titles at the left and an extra
space below the previous section. Section content is indented so it appears as part of the section.
Figure 10-5 shows the output from this code. Even though this help screen is quite simple, it pro-
vides everything needed for someone to use the example application to test command line switches.
Including Other Elements Some command line application help screens become enormous and hard to use. In fact, some of
Microsoft’s own utilities have help that’s several layers deep. Just try drilling into the
Net
utility
sometime and you’ll discover just how cumbersome the help can become. Of course, you do want to
document everything for the user. As an alternative, some command line application developers will
provide an overview as part of the application, and then include a URL for detailed material online.
It’s not a perfect solution because you can’t always count on the user having an Internet connection,
but it does work most of the time.
You don’t have to stop with simple information redirection as part of your help. Some utilities include
a phone number (just in case the user really is lacking that Internet connection). E-mail addresses aren’t
unusual, and some developers get creative in providing other helpful tips. It’s also important to take
ownership of your application by including a company or developer name. If copyright is important,
then you should provide a copyright notice as well. The thing is to make it easy for someone to identify
your command line application without cluttering up the help screens too much.
548592c10.indd 206
2/24/10 12:48:31 PM
www.finebook.ir