def printCategoryHelp( category, operators, listOperators, modifiers, operatorHelp ): printParagraph( 'The ' + category + ' category includes the following operators (with aliases in parentheses):' ) print( ) operatorList = [ key for key in operators if operatorHelp[ key ][ 0 ] == category ] operatorList.extend( [ key for key in listOperators if operatorHelp[ key ][ 0 ] == category ] ) operatorList.extend( [ key for key in modifiers if operatorHelp[ key ][ 0 ] == category ] ) addAliases( operatorList, g.operatorAliases ) for operator in sorted( operatorList ): print( operator )
def printHelp( operators, constants, listOperators, modifiers, term, interactive = False ): loadHelpData( ) if g.helpVersion != PROGRAM_VERSION: print( 'rpn: help file version mismatch' ) if term == '': if interactive: printInteractiveHelp( ) else: printGeneralHelp( ) return # first check if the term is an alias and translate if term in g.operatorAliases: term = g.operatorAliases[ term ] # then look for exact matches in all the lists of terms for which we have help support if term in operators: printOperatorHelp( term, operators[ term ], g.operatorHelp[ term ] ) elif term in constants: printOperatorHelp( term, constants[ term ], g.operatorHelp[ term ] ) elif term in listOperators: printOperatorHelp( term, listOperators[ term ], g.operatorHelp[ term ] ) elif term in modifiers: printOperatorHelp( term, modifiers[ term ], g.operatorHelp[ term ] ) elif term in g.helpTopics: print( g.helpTopics[ term ] ) elif term in g.operatorCategories: printCategoryHelp( term, operators, listOperators, modifiers, g.operatorHelp ) elif term == 'unit_types': printParagraph( ', '.join( sorted( g.unitTypeDict.keys( ) ) ), 4 ) elif term in g.unitTypeDict: unitList = sorted( g.unitTypeDict[ term ] ) addAliases( unitList, g.operatorAliases ) for unit in unitList: printParagraph( unit, 4 ) else: # if no exact matches for any topic, let's look for partial matches if 'unit_types'.startswith( term ): print( 'Interpreting topic as \'unit_types\'.' ) printParagraph( ', '.join( sorted( g.unitTypeDict.keys( ) ) ), 4 ) return helpTerm = next( ( i for i in g.unitTypeDict if i != term and i.startswith( term ) ), '' ) if helpTerm != '': print( ) print( 'Interpreting topic as \'' + helpTerm + '\'.' ) printParagraph( ', '.join( sorted( g.unitTypeDict[ helpTerm ] ) ), 4 ) return helpTerm = next( ( i for i in operators if i != term and i.startswith( term ) ), '' ) if helpTerm != '': print( 'Interpreting topic as \'' + helpTerm + '\'.' ) print( ) printOperatorHelp( helpTerm, operators[ helpTerm ], g.operatorHelp[ helpTerm ] ) return helpTerm = next( ( i for i in constants if i != term and i.startswith( term ) ), '' ) if helpTerm != '': print( 'Interpreting topic as \'' + helpTerm + '\'.' ) print( ) printOperatorHelp( helpTerm, constants[ helpTerm ], g.operatorHelp[ helpTerm ] ) return helpTerm = next( ( i for i in listOperators if i != term and i.startswith( term ) ), '' ) if helpTerm != '': print( 'Interpreting topic as \'' + helpTerm + '\'.' ) print( ) printOperatorHelp( helpTerm, listOperators[ helpTerm ], g.operatorHelp[ helpTerm ] ) return helpTerm = next( ( i for i in modifiers if i != term and i.startswith( term ) ), '' ) if helpTerm != '': print( 'Interpreting topic as \'' + helpTerm + '\'.' ) print( ) printOperatorHelp( helpTerm, modifiers[ helpTerm ], g.operatorHelp[ helpTerm ] ) return helpTerm = next( ( i for i in g.helpTopics if i != term and i.startswith( term ) ), '' ) if helpTerm != '': print( 'Interpreting topic as \'' + helpTerm + '\'.' ) print( ) print( g.helpTopics[ helpTerm ] ) return helpTerm = next( ( i for i in g.operatorCategories if i != term and i.startswith( term ) ), '' ) if helpTerm != '': print( 'Interpreting topic as \'' + helpTerm + '\'.' ) print( ) printCategoryHelp( helpTerm, operators, listOperators, modifiers, g.operatorHelp ) else: print( "Help topic not found." )