import sys

from core import KDPVGenerator


def print_help():
    print('Usage: python run.py [data.yml]')


def generate(filename):
    generator = KDPVGenerator.from_yml(filename)
    generator.generate()


def main():
    if len(sys.argv) < 2:
        filename = 'data.yml'

    else:
        filename = sys.argv[1]

    if filename in {'help', '-h', '--help'}:
        print_help()

    else:
        generate(filename)


if __name__ == '__main__':
    main()

import argparse
import os
from core import KDPVGenerator


def generate(filename):
    generator = KDPVGenerator.from_yml(filename)
    generator.generate()


def main():
    parser = argparse.ArgumentParser(description='KDPV Generator')
    parser.add_argument('filename', nargs='?', default='data.yml', help='data file (default: data.yml)')
    args = parser.parse_args()
    if not args.filename:
        parser.print_help()
    else:
        if not os.path.isfile(args.filename):
            exit('Unable to open file: {}'.format(args.filename))
        generate(args.filename)


if __name__ == '__main__':
    main()

Add argparse, handle data file missing
Add argparse, handle data file missing
+ import argparse
- import sys
+ import os
- 
  from core import KDPVGenerator
- 
- 
- def print_help():
-     print('Usage: python run.py [data.yml]')
  
  
  def generate(filename):
      generator = KDPVGenerator.from_yml(filename)
      generator.generate()
  
  
  def main():
-     if len(sys.argv) < 2:
-         filename = 'data.yml'
- 
+     parser = argparse.ArgumentParser(description='KDPV Generator')
+     parser.add_argument('filename', nargs='?', default='data.yml', help='data file (default: data.yml)')
+     args = parser.parse_args()
+     if not args.filename:
+         parser.print_help()
      else:
+         if not os.path.isfile(args.filename):
+             exit('Unable to open file: {}'.format(args.filename))
-         filename = sys.argv[1]
- 
-     if filename in {'help', '-h', '--help'}:
-         print_help()
- 
-     else:
-         generate(filename)
+         generate(args.filename)
  
  
  if __name__ == '__main__':
      main()
  
Add argparse, handle data file missing
## Code Before:
import sys

from core import KDPVGenerator


def print_help():
    print('Usage: python run.py [data.yml]')


def generate(filename):
    generator = KDPVGenerator.from_yml(filename)
    generator.generate()


def main():
    if len(sys.argv) < 2:
        filename = 'data.yml'

    else:
        filename = sys.argv[1]

    if filename in {'help', '-h', '--help'}:
        print_help()

    else:
        generate(filename)


if __name__ == '__main__':
    main()

## Instruction:
Add argparse, handle data file missing
## Code After:
import argparse
import os
from core import KDPVGenerator


def generate(filename):
    generator = KDPVGenerator.from_yml(filename)
    generator.generate()


def main():
    parser = argparse.ArgumentParser(description='KDPV Generator')
    parser.add_argument('filename', nargs='?', default='data.yml', help='data file (default: data.yml)')
    args = parser.parse_args()
    if not args.filename:
        parser.print_help()
    else:
        if not os.path.isfile(args.filename):
            exit('Unable to open file: {}'.format(args.filename))
        generate(args.filename)


if __name__ == '__main__':
    main()
