
from argparse import ArgumentParser
from glob import glob
from os import path

def is_valid_file(f, parser):
    if path.isfile(f):
        return f
    else:
        return parser.optparser.error("%s does not exist!" % f)

def parse_args():
    parser = ArgumentParser()

    parser.add_argument("--non-headless", action="store_true",
            help="do not use a virtual display")

    parser.add_argument("--crx", metavar='CRX_FILE_PATH', action="store",
            type=lambda x: is_valid_file(x, parser),
            default=max(glob("*.crx"), key=path.getmtime),
            help="path to Chrome extension CRX package")

    return parser.parse_args()


from glob import glob
from os import path

import argparse

def is_valid_file(f, parser):
    if path.isfile(f):
        return f
    raise argparse.ArgumentTypeError("%s does not exist!" % f)

def parse_args():
    parser = argparse.ArgumentParser()

    parser.add_argument("--non-headless", action="store_true",
            help="do not use a virtual display")

    parser.add_argument("--crx", metavar='CRX_FILE_PATH', action="store",
            type=lambda x: is_valid_file(x, parser),
            default=max(glob("*.crx"), key=path.getmtime),
            help="path to Chrome extension CRX package")

    return parser.parse_args()

Fix --crx arg error reporting.
Fix --crx arg error reporting.

  
- from argparse import ArgumentParser
  from glob import glob
  from os import path
+ 
+ import argparse
  
  def is_valid_file(f, parser):
      if path.isfile(f):
          return f
+     raise argparse.ArgumentTypeError("%s does not exist!" % f)
-     else:
-         return parser.optparser.error("%s does not exist!" % f)
  
  def parse_args():
-     parser = ArgumentParser()
+     parser = argparse.ArgumentParser()
  
      parser.add_argument("--non-headless", action="store_true",
              help="do not use a virtual display")
  
      parser.add_argument("--crx", metavar='CRX_FILE_PATH', action="store",
              type=lambda x: is_valid_file(x, parser),
              default=max(glob("*.crx"), key=path.getmtime),
              help="path to Chrome extension CRX package")
  
      return parser.parse_args()
  
Fix --crx arg error reporting.
## Code Before:

from argparse import ArgumentParser
from glob import glob
from os import path

def is_valid_file(f, parser):
    if path.isfile(f):
        return f
    else:
        return parser.optparser.error("%s does not exist!" % f)

def parse_args():
    parser = ArgumentParser()

    parser.add_argument("--non-headless", action="store_true",
            help="do not use a virtual display")

    parser.add_argument("--crx", metavar='CRX_FILE_PATH', action="store",
            type=lambda x: is_valid_file(x, parser),
            default=max(glob("*.crx"), key=path.getmtime),
            help="path to Chrome extension CRX package")

    return parser.parse_args()

## Instruction:
Fix --crx arg error reporting.
## Code After:

from glob import glob
from os import path

import argparse

def is_valid_file(f, parser):
    if path.isfile(f):
        return f
    raise argparse.ArgumentTypeError("%s does not exist!" % f)

def parse_args():
    parser = argparse.ArgumentParser()

    parser.add_argument("--non-headless", action="store_true",
            help="do not use a virtual display")

    parser.add_argument("--crx", metavar='CRX_FILE_PATH', action="store",
            type=lambda x: is_valid_file(x, parser),
            default=max(glob("*.crx"), key=path.getmtime),
            help="path to Chrome extension CRX package")

    return parser.parse_args()
