Update of /cvsroot/happydoc/HappyDoc/happydoclib
In directory usw-pr-cvs1:/tmp/cvs-serv27359/happydoclib
Modified Files:
CommandLineApp.py
Log Message:
Imported changes from pybox version.
Index: CommandLineApp.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/CommandLineApp.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** CommandLineApp.py 24 Dec 2001 19:02:54 -0000 1.7
--- CommandLineApp.py 17 Feb 2002 12:44:58 -0000 1.8
***************
*** 66,69 ****
--- 66,70 ----
#
import getopt
+ import pprint
import sys
import string
***************
*** 180,183 ****
--- 181,185 ----
self.showHelp(message)
raise getopt.error, message
+ return
def constructOptionInfo(self, methodName, methodRef):
***************
*** 257,264 ****
if option[0] == '-h':
self.showHelp()
! raise CommandLineApp.HelpRequested, 'Help message was printed.'
if option[0] == '--help':
self.showVerboseHelp()
! raise CommandLineApp.HelpRequested, 'Help message was printed.'
def main(self, *args):
--- 259,266 ----
if option[0] == '-h':
self.showHelp()
! raise self.HelpRequested, 'Help message was printed.'
if option[0] == '--help':
self.showVerboseHelp()
! raise self.HelpRequested, 'Help message was printed.'
def main(self, *args):
***************
*** 388,392 ****
# Print the argument description
#
! helpMsg = '%s\n\t%s' % (helpMsg, self.shortArgumentsDescription)
#
helpMsg = '%s\n\n' % helpMsg
--- 390,395 ----
# Print the argument description
#
! if self.shortArgumentsDescription:
! helpMsg = '%s\n\n\t\t%s' % (helpMsg, self.shortArgumentsDescription)
#
helpMsg = '%s\n\n' % helpMsg
***************
*** 419,424 ****
description_prefix = ' '
- docStringLines = string.split(docString, '\n')
optionString = '%s%s' % (baseString, description_prefix)
if docStringLines:
--- 422,427 ----
description_prefix = ' '
optionString = '%s%s' % (baseString, description_prefix)
+ docStringLines = string.split(docString, '\n')
if docStringLines:
***************
*** 488,494 ****
--- 491,506 ----
''
)
+
+ #
+ # Get a list of all unique option *names*
#
allOptionNames = self.allOptions.keys()
allOptionNames.sort()
+
+ #
+ # Figure out which options are aliases
+ #
+ option_aliases = {}
+ reduced_options = []
for option in allOptionNames:
optName, optTakesValue, optLongOrShort, ignore, ignore = \
***************
*** 496,527 ****
methodName = self.methodNameFromOption(option)
method = self.methodReferenceFromName(methodName)
! docString = method.__doc__
! if optTakesValue == self.optTakesParam:
! valueInsert = method.func_code.co_varnames[1]
! else:
! valueInsert = ''
! if optLongOrShort == self.optTypeLong:
! dashInsert = '--'
! if valueInsert:
! valueInsert = '=%s' % valueInsert
! else:
! dashInsert = '-'
! if valueInsert:
! valueInsert = ' %s' % valueInsert
helpMsg = string.join( [ helpMsg,
! self.getOptionHelpString(dashInsert,
! option,
! valueInsert,
! docString) ],
! '')
! #self.showOptionHelp(dashInsert, option, valueInsert, docString)
! helpMsg = helpMsg + '\n'
if self.argumentsDescription:
helpMsg = '%sARGUMENTS:\n\n%s\n\n' % (helpMsg,
self.argumentsDescription)
! #print 'ARGUMENTS:'
! #print ''
! #print self.argumentsDescription
! #print ''
return helpMsg
--- 508,571 ----
methodName = self.methodNameFromOption(option)
method = self.methodReferenceFromName(methodName)
! existing_aliases = option_aliases.get(method, [])
! if not existing_aliases:
! reduced_options.append(option)
! existing_aliases.append(option)
! option_aliases[method] = existing_aliases
!
! grouped_options = [ x[1] for x in option_aliases.items() ]
! grouped_options.sort()
!
! #
! # Describe all options, grouping aliases together
! #
!
! for option_set in grouped_options:
! first_option = option_set[0]
! #
! # Build the list of option name/parameter strings
! #
! option_help_strings = []
! for option in option_set:
! optName, optTakesValue, optLongOrShort, ignore, ignore = \
! self.infoForOption(option)
! methodName = self.methodNameFromOption(option)
! method = self.methodReferenceFromName(methodName)
! if optTakesValue == self.optTakesParam:
! valueInsert = method.func_code.co_varnames[1]
! else:
! valueInsert = ''
! if optLongOrShort == self.optTypeLong:
! dashInsert = '--'
! if valueInsert:
! valueInsert = '=%s' % valueInsert
! else:
! dashInsert = '-'
! if valueInsert:
! valueInsert = ' %s' % valueInsert
! option_help_strings.append('%s%s%s' % (dashInsert,
! optName,
! valueInsert,
! )
! )
! option_help_string = ', '.join(option_help_strings)
!
! methodName = self.methodNameFromOption(first_option)
! method = self.methodReferenceFromName(methodName)
! docString = method.__doc__.rstrip()
helpMsg = string.join( [ helpMsg,
! self.getOptionHelpString('',
! option_help_string,
! '',
! docString,
! )
! ],
! '')
! helpMsg = helpMsg + '\n'
!
if self.argumentsDescription:
helpMsg = '%sARGUMENTS:\n\n%s\n\n' % (helpMsg,
self.argumentsDescription)
!
return helpMsg
***************
*** 565,570 ****
"Display help message when error occurs."
print
! print '%s version %s' % (self.__class__.__name__, self._app_version)
print
#
# If they made a syntax mistake, just
--- 609,618 ----
"Display help message when error occurs."
print
! if self._app_version:
! print '%s version %s' % (self.__class__.__name__, self._app_version)
! else:
! print self.__class__.__name__
print
+
#
# If they made a syntax mistake, just
***************
*** 730,734 ****
SubClassTestApp version 0.0
! ./test_happydoc.py [-hbqvz]
[-a newA]
[--help]
--- 778,782 ----
SubClassTestApp version 0.0
! %s [-hbqvz]
[-a newA]
[--help]
***************
*** 736,745 ****
[--long-form-with-value=optValue]
[--option-list=optionList]
-
For more details, use --help.
! """
assert help_text == expected_help_text, \
'Unexpected help text "%s" does not match "%s"' % (help_text, expected_help_text)
--- 784,792 ----
[--long-form-with-value=optValue]
[--option-list=optionList]
For more details, use --help.
! """ % sys.argv[0]
assert help_text == expected_help_text, \
'Unexpected help text "%s" does not match "%s"' % (help_text, expected_help_text)
***************
*** 749,754 ****
help_text = self.runAndCatchOutput(['--help'])
expected_help_text = """
! ./test_happydoc.py
--- 796,802 ----
help_text = self.runAndCatchOutput(['--help'])
+ app = sys.argv[0]
expected_help_text = """
! %(app)s
***************
*** 758,762 ****
SYNTAX:
! ./test_happydoc.py [-hbqvz]
[-a newA]
[--help]
--- 806,810 ----
SYNTAX:
! %(app)s [-hbqvz]
[-a newA]
[--help]
***************
*** 764,768 ****
[--long-form-with-value=optValue]
[--option-list=optionList]
-
OPTIONS:
--- 812,815 ----
***************
*** 774,782 ****
--- 821,832 ----
-a newA Doc string for SubClassTestApp
+
-b toggle the value of b
+
--long-form-option
boolean option
+
--long-form-with-value=optValue
First line of help.
***************
*** 785,797 ****
Default:<manually inserted>
--option-list=optionList
Doc string for SubClassTestApp
-q Turn on quiet mode.
-v Increment the verbose level.
Higher levels are more verbose.
The default is 1.
!
-z Doc string for SubClassTestApp
--- 835,850 ----
Default:<manually inserted>
+
--option-list=optionList
Doc string for SubClassTestApp
+
-q Turn on quiet mode.
+
-v Increment the verbose level.
Higher levels are more verbose.
The default is 1.
!
-z Doc string for SubClassTestApp
***************
*** 810,815 ****
! """
! assert help_text == expected_help_text, 'Unexpected help text "%s"' % help_text
return
--- 863,868 ----
! """ % locals()
! assert help_text == expected_help_text, 'Unexpected help text "%s" does not match "%s"' % (help_text, expected_help_text)
return
|