528def main(args=sys.argv):
529 """
530 Main command line entry point.
531 """
532 desc = "Highlight an input file and write the result to an output file."
534 formatter_class=HelpFormatter)
535
539 '-l', metavar='LEXER',
540 help='Specify the lexer to use. (Query names with -L.) If not '
541 'given and -g is not present, the lexer is guessed from the filename.')
543 '-g', action='store_true',
544 help='Guess the lexer from the file contents, or pass through '
545 'as plain text if nothing can be guessed.')
547 '-F', metavar='FILTER[:options]', action='append',
548 help='Add a filter to the token stream. (Query names with -L.) '
549 'Filter options are given after a colon if necessary.')
551 '-f', metavar='FORMATTER',
552 help='Specify the formatter to use. (Query names with -L.) '
553 'If not given, the formatter is guessed from the output filename, '
554 'and defaults to the terminal formatter if the output is to the '
555 'terminal or an unknown file extension.')
557 '-O', metavar='OPTION=value[,OPTION=value,...]', action='append',
558 help='Give options to the lexer and formatter as a comma-separated '
559 'list of key-value pairs. '
560 'Example: `-O bg=light,python=cool`.')
562 '-P', metavar='OPTION=value', action='append',
563 help='Give a single option to the lexer and formatter - with this '
564 'you can pass options whose value contains commas and equal signs. '
565 'Example: `-P "heading=Pygments, the Python highlighter"`.')
567 '-o', metavar='OUTPUTFILE',
568 help='Where to write the output. Defaults to standard output.')
569
571 'INPUTFILE', nargs='?',
572 help='Where to read the input. Defaults to standard input.')
573
576 '-v', action='store_true',
577 help='Print a detailed traceback on unhandled exceptions, which '
578 'is useful for debugging and bug reports.')
580 '-s', action='store_true',
581 help='Process lines one at a time until EOF, rather than waiting to '
582 'process the entire file. This only works for stdin, only for lexers '
583 'with no line-spanning constructs, and is intended for streaming '
584 'input such as you get from `tail -f`. '
585 'Example usage: `tail -f sql.log | pygmentize -s -l sql`.')
587 '-x', action='store_true',
588 help='Allow custom lexers and formatters to be loaded from a .py file '
589 'relative to the current working directory. For example, '
590 '`-l ./customlexer.py -x`. By default, this option expects a file '
591 'with a class named CustomLexer or CustomFormatter; you can also '
592 'specify your own class name with a colon (`-l ./lexer.py:MyLexer`). '
593 'Users should be very careful not to use this option with untrusted '
594 'files, because it will import and run them.')
596 'be only used in conjunction with -L.',
597 default=False,
598 action='store_true')
599
601 'Special modes - do not do any highlighting')
604 '-S', metavar='STYLE -f formatter',
605 help='Print style definitions for STYLE for a formatter '
606 'given with -f. The argument given by -a is formatter '
607 'dependent.')
609 '-L', nargs='*', metavar='WHAT',
610 help='List lexers, formatters, styles or filters -- '
611 'give additional arguments for the thing(s) you want to list '
612 '(e.g. "styles"), or omit them to list everything.')
614 '-N', metavar='FILENAME',
615 help='Guess and print out a lexer name based solely on the given '
616 'filename. Does not take input or highlight anything. If no specific '
617 'lexer can be determined, "text" is printed.')
619 '-C', action='store_true',
620 help='Like -N, but print out a lexer name based solely on '
621 'a given content from standard input.')
623 '-H', action='store', nargs=2, metavar=('NAME', 'TYPE'),
624 help='Print detailed help for the object <name> of type <type>, '
625 'where <type> is one of "lexer", "formatter" or "filter".')
627 '-V', action='store_true',
628 help='Print the package version.')
630 '-h', '--help', action='store_true',
631 help='Print this help.')
633 '-a', metavar='ARG',
634 help='Formatter-specific additional argument for the -S (print '
635 'style sheet) mode.')
636
638
639 try:
640 return main_inner(parser, argns)
641 except BrokenPipeError:
642
643 return 0
644 except Exception:
648 print('An unhandled exception occurred while highlighting.',
650 print('Please report the whole traceback to the issue tracker at',
652 print('<https://github.com/pygments/pygments/issues>.',
656 raise
657 import traceback
659 msg = info[-1].strip()
661
662 msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:]
664 print(
'*** Error while highlighting:', file=
sys.stderr)
666 print('*** If this is a bug you want to report, please rerun with -v.',
668 return 1