def printInteractiveHelp( ): loadHelpData( ) printParagraph( '''For help on a specific topic, use the topic operator with a general topic, operator category or a specific operator name.''' ) print( ) print( 'The following is a list of general topics:' ) print( ) helpTopics = list( g.helpTopics.keys( ) ) helpTopics.append( 'unit_types' ) printParagraph( ', '.join( sorted( helpTopics ) ), 4 ) print( ) print( 'The following is a list of operator categories:' ) print( ) printParagraph( ', '.join( sorted( g.operatorCategories ) ), 4 )
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." )