code: def main(args=sys.argv):
      """
      Main command line entry point.
      """
      desc = "Highlight an input file and write the result to an output file."
      parser = argparse.ArgumentParser(
          description=desc,
          add_help=False,
          formatter_class=HelpFormatter,
      )
  
      operation = parser.add_argument_group("Main operation")
      lexersel = operation.add_mutually_exclusive_group()
      lexersel.add_argument(
          "-l",
          metavar="LEXER",
          help="Specify the lexer to use.  (Query names with -L.)  If not "
          "given and -g is not present, the lexer is guessed from the filename.",
      )
      lexersel.add_argument(
          "-g",
          action="store_true",
          help="Guess the lexer from the file contents, or pass through "
          "as plain text if nothing can be guessed.",
      )
      operation.add_argument(
          "-F",
          metavar="FILTER[:options]",
          action="append",
          help="Add a filter to the token stream.  (Query names with -L.) "
          "Filter options are given after a colon if necessary.",
      )
      operation.add_argument(
          "-f",
          metavar="FORMATTER",
          help="Specify the formatter to use.  (Query names with -L.) "
          "If not given, the formatter is guessed from the output filename, "
          "and defaults to the terminal formatter if the output is to the "
          "terminal or an unknown file extension.",
      )
      operation.add_argument(
          "-O",
          metavar="OPTION=value[,OPTION=value,...]",
          action="append",
          help="Give options to the lexer and formatter as a comma-separated "
          "list of key-value pairs. "
          "Example: `-O bg=light,python=cool`.",
      )
      operation.add_argument(
          "-P",
          metavar="OPTION=value",
          action="append",
          help="Give a single option to the lexer and formatter - with this "
          "you can pass options whose value contains commas and equal signs. "
          'Example: `-P "heading=Pygments, the Python highlighter"`.',
      )
      operation.add_argument(
          "-o",
          metavar="OUTPUTFILE",
          help="Where to write the output.  Defaults to standard output.",
      )
  
      operation.add_argument(
          "INPUTFILE",
          nargs="?",
          help="Where to read the input.  Defaults to standard input.",
      )
  
      flags = parser.add_argument_group("Operation flags")
      flags.add_argument(
          "-v",
          action="store_true",
          help="Print a detailed traceback on unhandled exceptions, which "
          "is useful for debugging and bug reports.",
      )
      flags.add_argument(
          "-s",
          action="store_true",
          help="Process lines one at a time until EOF, rather than waiting to "
          "process the entire file.  This only works for stdin, only for lexers "
          "with no line-spanning constructs, and is intended for streaming "
          "input such as you get from `tail -f`. "
          "Example usage: `tail -f sql.log | pygmentize -s -l sql`.",
      )
      flags.add_argument(
          "-x",
          action="store_true",
          help="Allow custom lexers and formatters to be loaded from a .py file "
          "relative to the current working directory. For example, "
          "`-l ./customlexer.py -x`. By default, this option expects a file "
          "with a class named CustomLexer or CustomFormatter; you can also "
          "specify your own class name with a colon (`-l ./lexer.py:MyLexer`). "
          "Users should be very careful not to use this option with untrusted "
          "files, because it will import and run them.",
      )
      flags.add_argument(
          "--json",
          help="Output as JSON. This can "
          "be only used in conjunction with -L.",
          default=False,
          action="store_true",
      )
  
      special_modes_group = parser.add_argument_group(
          "Special modes - do not do any highlighting"
      )
      special_modes = special_modes_group.add_mutually_exclusive_group()
      special_modes.add_argument(
          "-S",
          metavar="STYLE -f formatter",
          help="Print style definitions for STYLE for a formatter "
          "given with -f. The argument given by -a is formatter "
          "dependent.",
      )
      special_modes.add_argument(
          "-L",
          nargs="*",
          metavar="WHAT",
          help="List lexers, formatters, styles or filters -- "
          "give additional arguments for the thing(s) you want to list "
          '(e.g. "styles"), or omit them to list everything.',
      )
      special_modes.add_argument(
          "-N",
          metavar="FILENAME",
          help="Guess and print out a lexer name based solely on the given "
          "filename. Does not take input or highlight anything. If no specific "
          'lexer can be determined, "text" is printed.',
      )
      special_modes.add_argument(
          "-C",
          action="store_true",
          help="Like -N, but print out a lexer name based solely on "
          "a given content from standard input.",
      )
      special_modes.add_argument(
          "-H",
          action="store",
          nargs=2,
          metavar=("NAME", "TYPE"),
          help="Print detailed help for the object <name> of type <type>, "
          'where <type> is one of "lexer", "formatter" or "filter".',
      )
      special_modes.add_argument(
          "-V", action="store_true", help="Print the package version."
      )
      special_modes.add_argument(
          "-h", "--help", action="store_true", help="Print this help."
      )
      special_modes_group.add_argument(
          "-a",
          metavar="ARG",
          help="Formatter-specific additional argument for the -S (print "
          "style sheet) mode.",
      )
  
      argns = parser.parse_args(args[1:])
  
      try:
          return main_inner(parser, argns)
      except BrokenPipeError:
          # someone closed our stdout, e.g. by quitting a pager.
          return 0
      except Exception:
          if argns.v:
              print(file=sys.stderr)
              print("*" * 65, file=sys.stderr)
              print(
                  "An unhandled exception occurred while highlighting.",
                  file=sys.stderr,
              )
              print(
                  "Please report the whole traceback to the issue tracker at",
                  file=sys.stderr,
              )
              print(
                  "<https://github.com/pygments/pygments/issues>.",
                  file=sys.stderr,
              )
              print("*" * 65, file=sys.stderr)
              print(file=sys.stderr)
              raise
          import traceback
  
          info = traceback.format_exception(*sys.exc_info())
          msg = info[-1].strip()
          if len(info) >= 3:
              # extract relevant file and position info
              msg += "\n   (f%s)" % info[-2].split("\n")[0].strip()[1:]
          print(file=sys.stderr)
          print("*** Error while highlighting:", file=sys.stderr)
          print(msg, file=sys.stderr)
          print(
              "*** If this is a bug you want to report, please rerun with -v.",
              file=sys.stderr,
          )
          return 1
  
imports: import os
  import sys
  import shutil
  import argparse
  from textwrap import dedent
  from pygments import __version__, highlight
  from pygments.util import ClassNotFound, OptionError, docstring_headline, guess_decode, guess_decode_from_terminal, terminal_encoding, UnclosingTextIOWrapper
  from pygments.lexers import get_all_lexers, get_lexer_by_name, guess_lexer, load_lexer_from_file, get_lexer_for_filename, find_lexer_class_for_filename
  from pygments.lexers.special import TextLexer
  from pygments.formatters.latex import LatexEmbeddedLexer, LatexFormatter
  from pygments.formatters import get_all_formatters, get_formatter_by_name, load_formatter_from_file, get_formatter_for_filename, find_formatter_class
  from pygments.formatters.terminal import TerminalFormatter
  from pygments.formatters.terminal256 import Terminal256Formatter, TerminalTrueColorFormatter
  from pygments.filters import get_all_filters, find_filter_class
  from pygments.styles import get_all_styles, get_style_by_name
label_desc: Use image node_id 7 for calling a global function with example usage: main(args) and returns: main_inner, int, int