#NEWLINE# def help( self , value , via ) : #NEWLINE# #INDENT# 'Display a GNU-ish help page listing arguments and possible sub-commands.' #NEWLINE# width = self . width ( ) #NEWLINE# for ( i , spec ) in enumerate ( self . stack ) : #NEWLINE# #INDENT# ( summary , description ) = ( spec . doc or ( None , None ) ) #NEWLINE# if ( not i ) : #NEWLINE# #INDENT# if summary : #NEWLINE# #INDENT# print ( wrap ( summary , width ) ) #NEWLINE# #UNINDENT# print ( 'Usage:' , os . path . basename ( sys . argv [ 0 ] ) , end = ' ' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( spec . callable . __name__ , end = ' ' ) #NEWLINE# #UNINDENT# if spec . named : #NEWLINE# #INDENT# print ( ( '[CMDOPTS]' if i else '[OPTIONS]' ) , end = ' ' ) #NEWLINE# #UNINDENT# if spec . keyed : #NEWLINE# #INDENT# print ( '[--name=value...]' , end = ' ' ) #NEWLINE# #UNINDENT# for arg in spec . positional : #NEWLINE# #INDENT# print ( '<' , arg , '>' , sep = '' , end = ' ' ) #NEWLINE# #UNINDENT# if spec . indexed : #NEWLINE# #INDENT# print ( '[value...]' , end = ' ' ) #NEWLINE# #UNINDENT# if ( spec . cls and ( len ( self . stack ) == ( i + 1 ) ) ) : #NEWLINE# #INDENT# print ( '<COMMAND> ...' , end = '' ) #NEWLINE# #UNINDENT# #UNINDENT# print ( ) #NEWLINE# for ( i , spec ) in enumerate ( self . stack ) : #NEWLINE# #INDENT# ( summary , description ) = ( spec . doc or ( None , None ) ) #NEWLINE# if i : #NEWLINE# #INDENT# print ( '\nCommand:' , spec . callable . __name__ ) #NEWLINE# if summary : #NEWLINE# #INDENT# print ( wrap ( summary , width ) ) #NEWLINE# #UNINDENT# #UNINDENT# if spec . named : #NEWLINE# #INDENT# print ( '\n' , ( 'CMDOPTS' if i else 'OPTIONS' ) , ' may be one or more of:' , sep = '' , end = '\n\n' ) #NEWLINE# strings = dict ( ) #NEWLINE# abbreviation = dict ( zip ( spec . short . values ( ) , spec . short . keys ( ) ) ) #NEWLINE# pretty = dict ( zip ( spec . trans . values ( ) , spec . trans . keys ( ) ) ) #NEWLINE# for name in spec . named : #NEWLINE# #INDENT# default = spec . defaults . get ( name ) #NEWLINE# if ( spec . cast . get ( name , None ) is boolean ) : #NEWLINE# #INDENT# strings [ ( ( ( ( ( '-' + abbreviation [ name ] ) + ', ' ) if ( name in abbreviation ) else '' ) + '--' ) + pretty . get ( name , name ) ) ] = spec . docs . get ( name , ( 'Toggle this value.\nDefault: %r' % default ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# strings [ ( ( ( ( '-' + abbreviation [ name ] ) + ', --' ) + pretty . get ( name , name ) ) + '=VAL' ) ] = spec . docs . get ( name , ( 'Override this value.\nDefault: %r' % default ) ) #NEWLINE# #UNINDENT# mlen = max ( [ len ( j ) for j in strings ] ) #NEWLINE# for name in sorted ( strings ) : #NEWLINE# #INDENT# print ( ( ' %-*s  %s' % ( mlen , name , wrap ( strings [ name ] , width ) . replace ( '\n' , ( '\n' + ( ' ' * ( i + 3 ) ) ) ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( spec . cls and ( len ( self . stack ) == ( i + 1 ) ) ) : #NEWLINE# #INDENT# print ( '\n' , 'COMMAND may be one of:' , sep = '' , end = '\n\n' ) #NEWLINE# cmds = dict ( ) #NEWLINE# for cmd in dir ( spec . target ) : #NEWLINE# #INDENT# if ( ( cmd [ 0 ] == '_' ) or ( not callable ( getattr ( spec . target , cmd ) ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# cmds [ cmd ] = partitionhelp ( ( getdoc ( getattr ( spec . target , cmd ) ) or 'Undocumented command.' ) ) [ 0 ] #NEWLINE# #UNINDENT# mlen = max ( [ len ( i ) for i in cmds ] ) #NEWLINE# for name in sorted ( cmds ) : #NEWLINE# #INDENT# print ( ( ' %-*s  %s' % ( mlen , name , wrap ( cmds [ name ] , width ) . replace ( '\n' , ( '\n' + ( ' ' * ( mlen + 3 ) ) ) ) ) ) ) #NEWLINE# #UNINDENT# print ( '\n' , wrap ( 'For help on a specific command, call the command and pass --help in CMDOPTS.' , width ) , sep = '' ) #NEWLINE# #UNINDENT# if description : #NEWLINE# #INDENT# print ( '\n' , wrap ( description , width ) , sep = '' ) #NEWLINE# #UNINDENT# #UNINDENT# print ( ) #NEWLINE# raise ExitException ( os . EX_USAGE , None )