text: #!/usr/bin/env python2
  """
  flag_def.py
  """
  from __future__ import print_function
  
  from frontend import args
  from frontend.flag_spec import (
      FlagSpec, FlagSpecAndMore, _FlagSpecAndMore
  )
  from frontend import option_def
  
  #
  # Definitions for builtin_assign
  #
  
  EXPORT_SPEC = FlagSpec('export_')
  EXPORT_SPEC.ShortFlag('-n')
  EXPORT_SPEC.ShortFlag('-f')  # stubbed
  EXPORT_SPEC.ShortFlag('-p')
  
  
  READONLY_SPEC = FlagSpec('readonly')
  
  # TODO: Check the consistency of -a and -A against values, here and below.
  READONLY_SPEC.ShortFlag('-a')
  READONLY_SPEC.ShortFlag('-A')
  READONLY_SPEC.ShortFlag('-p')
  
  
  NEW_VAR_SPEC = FlagSpec('new_var')
  
  # print stuff
  NEW_VAR_SPEC.ShortFlag('-f')
  NEW_VAR_SPEC.ShortFlag('-F')
  NEW_VAR_SPEC.ShortFlag('-p')
  
  NEW_VAR_SPEC.ShortFlag('-g')  # Look up in global scope
  
  # Options +r +x +n
  NEW_VAR_SPEC.PlusFlag('x')  # export
  NEW_VAR_SPEC.PlusFlag('r')  # readonly
  NEW_VAR_SPEC.PlusFlag('n')  # named ref
  
  # Common between readonly/declare
  NEW_VAR_SPEC.ShortFlag('-a')
  NEW_VAR_SPEC.ShortFlag('-A')
  
  
  UNSET_SPEC = FlagSpec('unset')
  UNSET_SPEC.ShortFlag('-v')
  UNSET_SPEC.ShortFlag('-f')
  #UNSET_SPEC.ShortFlag('-z', args.String)
  
  #
  # Definitions for builtin_meta
  #
  
  # Unused because there are no flags!  Just --.
  EVAL_SPEC = FlagSpec('eval')
  EVAL_SPEC = FlagSpec('source')
  
  COMMAND_SPEC = FlagSpec('command')
  COMMAND_SPEC.ShortFlag('-v')
  # COMMAND_SPEC.ShortFlag('-V')  # Another verbose mode.
  
  TYPE_SPEC = FlagSpec('type')
  TYPE_SPEC.ShortFlag('-f')
  TYPE_SPEC.ShortFlag('-t')
  TYPE_SPEC.ShortFlag('-p')
  TYPE_SPEC.ShortFlag('-P')
  
  
  #
  # Definitions for builtin_pure
  #
  
  ALIAS_SPEC = FlagSpec('alias')  # no flags yet
  UNALIAS_SPEC = FlagSpec('unalias')  # no flags yet
  
  SHOPT_SPEC = FlagSpec('shopt')
  SHOPT_SPEC.ShortFlag('-s', long_name='--set')
  SHOPT_SPEC.ShortFlag('-u', long_name='--unset')
  SHOPT_SPEC.ShortFlag('-o')  # use 'set -o' names
  # TODO: --print could print in a verbose format.  (Annoying: codegen conflicts
  # with Python keyword.)
  SHOPT_SPEC.ShortFlag('-p')
  SHOPT_SPEC.ShortFlag('-q')  # query option settings
  
  
  HASH_SPEC = FlagSpec('hash')
  HASH_SPEC.ShortFlag('-r')
  
  
  ECHO_SPEC = FlagSpec('echo')
  ECHO_SPEC.ShortFlag('-e')  # no backslash escapes
  ECHO_SPEC.ShortFlag('-n')
  
  #
  # osh/builtin_printf.py
  #
  
  
  PRINTF_SPEC = FlagSpec('printf')
  PRINTF_SPEC.ShortFlag('-v', args.String)
  
  #
  # osh/builtin_misc.py
  #
  
  READ_SPEC = FlagSpec('read')
  READ_SPEC.ShortFlag('-r')
  READ_SPEC.ShortFlag('-s')  # silent
  READ_SPEC.ShortFlag('-u', args.Int)  # file descriptor
  READ_SPEC.ShortFlag('-t', args.Float)  # timeout
  READ_SPEC.ShortFlag('-n', args.Int)
  READ_SPEC.ShortFlag('-a', args.String)  # name of array to read into
  READ_SPEC.ShortFlag('-d', args.String)
  READ_SPEC.ShortFlag('-p', args.String)  # prompt
  
  # Oil extensions
  READ_SPEC.ShortFlag('-0')  # until NUL, like -r -d ''
  READ_SPEC.LongFlag('--all')
  READ_SPEC.LongFlag('--line')
  # don't strip the trailing newline
  READ_SPEC.LongFlag('--with-eol')
  # Decode QSN after reading a line.  Note: A QSN string can't have literal
  # newlines or tabs; they must be escaped.
  READ_SPEC.ShortFlag('-q', long_name='--qsn')
  
  
  MAPFILE_SPEC = FlagSpec('mapfile')
  MAPFILE_SPEC.ShortFlag('-t')
  
  
  CD_SPEC = FlagSpec('cd')
  CD_SPEC.ShortFlag('-L')
  CD_SPEC.ShortFlag('-P')
  
  
  DIRS_SPEC = FlagSpec('dirs')
  DIRS_SPEC.ShortFlag('-c')
  DIRS_SPEC.ShortFlag('-l')
  DIRS_SPEC.ShortFlag('-p')
  DIRS_SPEC.ShortFlag('-v')
  
  
  PWD_SPEC = FlagSpec('pwd')
  PWD_SPEC.ShortFlag('-L')
  PWD_SPEC.ShortFlag('-P')
  
  
  HELP_SPEC = FlagSpec('help')
  # Use Oil flags?  -index?
  #HELP_SPEC.ShortFlag('-i')  # show index
  # Note: bash has help -d -m -s, which change the formatting
  
  
  HISTORY_SPEC = FlagSpec('history')
  HISTORY_SPEC.ShortFlag('-c')
  HISTORY_SPEC.ShortFlag('-d', args.Int)
  
  #
  # osh/builtin_process.py
  #
  
  WAIT_SPEC = FlagSpec('wait')
  WAIT_SPEC.ShortFlag('-n')
  
  
  TRAP_SPEC = FlagSpec('trap')
  TRAP_SPEC.ShortFlag('-p')
  TRAP_SPEC.ShortFlag('-l')
  
  JOB_SPEC = FlagSpec('jobs')
  JOB_SPEC.ShortFlag('-l', help='long format')
  JOB_SPEC.LongFlag('--debug', help='display debug info')
  
  #
  # FlagSpecAndMore
  #
  
  #
  # set and shopt
  #
  
  def _AddShellOptions(spec):
    # type: (_FlagSpecAndMore) -> None
    """Shared between 'set' builtin and the shell's own arg parser."""
    spec.InitOptions()
    spec.InitShopt()
  
    for opt in option_def.All():
      if opt.builtin == 'set':
        spec.Option(opt.short_flag, opt.name)
      # Notes:
      # - shopt option don't need to be registered; we validate elsewhere
      # - 'interactive' Has a cell for internal use, but isn't allowed to be
      # modified.
  
  
  OSH_SPEC = FlagSpecAndMore('main', typed=True)
  
  OSH_SPEC.ShortFlag('-c', args.String, quit_parsing_flags=True)  # command string
  OSH_SPEC.LongFlag('--help')
  OSH_SPEC.LongFlag('--version')
  
  OSH_SPEC.ShortFlag('-i')  # interactive
  OSH_SPEC.ShortFlag('-l')  # login - currently no-op
  OSH_SPEC.LongFlag('--login')  # login - currently no-op
  OSH_SPEC.LongFlag('--headless')  # accepts ECMD, etc.
  
  # TODO: -h too
  # the output format when passing -n
  OSH_SPEC.LongFlag('--ast-format',
      ['text', 'abbrev-text', 'html', 'abbrev-html', 'oheap', 'none'],
      default='abbrev-text')
  
  # Defines completion style.
  OSH_SPEC.LongFlag('--completion-display', ['minimal', 'nice'], default='nice')
  # TODO: Add option for Oil prompt style?  RHS prompt?
  
  # Don't reparse a[x+1] and ``.  Only valid in -n mode.
  OSH_SPEC.LongFlag('--one-pass-parse')
  
  OSH_SPEC.LongFlag('--print-status')  # TODO: Replace with a shell hook
  OSH_SPEC.LongFlag('--debug-file', args.String)
  OSH_SPEC.LongFlag('--xtrace-to-debug-file')
  
  # For benchmarks/*.sh
  OSH_SPEC.LongFlag('--parser-mem-dump', args.String)
  OSH_SPEC.LongFlag('--runtime-mem-dump', args.String)
  
  # This flag has is named like bash's equivalent.  We got rid of --norc because
  # it can simply by --rcfile /dev/null.
  OSH_SPEC.LongFlag('--rcfile', args.String)
  
  _AddShellOptions(OSH_SPEC)
  
  
  SET_SPEC = FlagSpecAndMore('set', typed=True)
  _AddShellOptions(SET_SPEC)
  
  
  #
  # Pure Oil
  #
  
  
  TRY_SPEC = FlagSpec('try_')
  TRY_SPEC.LongFlag('--assign', args.String,
      help='Assign status to this variable, and return 0')
  TRY_SPEC.LongFlag('--allow-status-01', args.Bool,
      help='Return 0 or 1 status values, but fail for others (e.g. for grep)')
  
  # Future directions:
  # run --allow-status=0,1
  #   an arbitrary list of statuses.  Although --assign does this just
  #   fine.
  # run --builtin, run --command, run --proc:
  #   to "replace" 'builtin' and # 'command'
  
  
  APPEND_SPEC = FlagSpec('append')
  
  SHVAR_SPEC = FlagSpec('shvar')
  #SHVAR_SPEC.Flag('-temp', args.String,
  #    help='Push a NAME=val binding')
  #SHVAR_SPEC.Flag('-env', args.String,
  #    help='Push a NAME=val binding and set the -x flag')
  
  PP_SPEC = FlagSpec('pp')
  
  # --verbose?
  FORK_SPEC = FlagSpec('fork')
  FORKWAIT_SPEC = FlagSpec('forkwait')
  
  # Might want --list at some point
  MODULE_SPEC = FlagSpec('module')
  
  RUNPROC_SPEC = FlagSpec('runproc')
  RUNPROC_SPEC.ShortFlag('-h', args.Bool, help='Show all procs')
  
  WRITE_SPEC = FlagSpec('write')
  WRITE_SPEC.LongFlag(
      '--sep', args.String, default='\n',
      help='Characters to separate each argument')
  WRITE_SPEC.LongFlag(
      '--end', args.String, default='\n',
      help='Characters to terminate the whole invocation')
  WRITE_SPEC.ShortFlag(
      '-n', args.Bool,
      help="Omit newline (synonym for -end '')")
  WRITE_SPEC.LongFlag(
      '--qsn', args.Bool, default=False,
      help='Write elements in QSN format')
  
  # x means I want \x00
  # u means I want \u{1234}
  # raw is utf-8
  # might also want: maybe?
  WRITE_SPEC.LongFlag(
      '--unicode', ['raw', 'u', 'x',], default='raw',
      help='Encode QSN with these options.  '
           'x assumes an opaque byte string, while raw and u try to '
           'decode UTF-8.')
  
  
  
  #
  # Tea
  #
  
  TEA_MAIN_SPEC = FlagSpec('tea_main')
  TEA_MAIN_SPEC.ShortFlag('-n', args.Bool)  # Parse
  TEA_MAIN_SPEC.ShortFlag('-c', args.String)  # Command snippet
  TEA_MAIN_SPEC.LongFlag('--translate', args.Bool)
  
  