from redux.codegenerator import compile_script
from argparse import ArgumentParser
from os.path import splitext

parser = ArgumentParser(description='Compile a Redux script to Rescript.')
parser.add_argument('filenames', metavar='FILE', nargs='+',
                    help='script to be compiled to Rescript')

args = parser.parse_args()

for filename in args.filenames:
    with open(filename, "rt") as file_:
        input_code = file_.read()

    base_filename, extension = splitext(filename)
    with open(base_filename + ".ais", "wt") as file_:
        file_.write(compile_script(filename, input_code))

from redux.codegenerator import compile_script
from argparse import ArgumentParser
from os.path import splitext

parser = ArgumentParser(description='Compile a Redux script to Rescript.')
parser.add_argument('input_filename', metavar='FILE',
                    help='script to be compiled to Rescript')
parser.add_argument('output_filename', metavar='FILE',
                    help='script to be compiled to Rescript')

args = parser.parse_args()

filename = args.input_filename
assert filename, "no input file given"

with open(filename, "rt") as file_:
    input_code = file_.read()

output_code = compile_script(filename, input_code)

base_filename, extension = splitext(filename)
with open(args.output_filename, "wt") as file_:
    file_.write(output_code)

Make compiler invocation more Makefile-friendly
Make compiler invocation more Makefile-friendly

  from redux.codegenerator import compile_script
  from argparse import ArgumentParser
  from os.path import splitext
  
  parser = ArgumentParser(description='Compile a Redux script to Rescript.')
- parser.add_argument('filenames', metavar='FILE', nargs='+',
+ parser.add_argument('input_filename', metavar='FILE',
+                     help='script to be compiled to Rescript')
+ parser.add_argument('output_filename', metavar='FILE',
                      help='script to be compiled to Rescript')
  
  args = parser.parse_args()
  
- for filename in args.filenames:
+ filename = args.input_filename
+ assert filename, "no input file given"
-     with open(filename, "rt") as file_:
-         input_code = file_.read()
  
-     base_filename, extension = splitext(filename)
-     with open(base_filename + ".ais", "wt") as file_:
+ with open(filename, "rt") as file_:
-         file_.write(compile_script(filename, input_code))
+     input_code = file_.read()
  
+ output_code = compile_script(filename, input_code)
+ 
+ base_filename, extension = splitext(filename)
+ with open(args.output_filename, "wt") as file_:
+     file_.write(output_code)
+ 
Make compiler invocation more Makefile-friendly
## Code Before:
from redux.codegenerator import compile_script
from argparse import ArgumentParser
from os.path import splitext

parser = ArgumentParser(description='Compile a Redux script to Rescript.')
parser.add_argument('filenames', metavar='FILE', nargs='+',
                    help='script to be compiled to Rescript')

args = parser.parse_args()

for filename in args.filenames:
    with open(filename, "rt") as file_:
        input_code = file_.read()

    base_filename, extension = splitext(filename)
    with open(base_filename + ".ais", "wt") as file_:
        file_.write(compile_script(filename, input_code))

## Instruction:
Make compiler invocation more Makefile-friendly
## Code After:
from redux.codegenerator import compile_script
from argparse import ArgumentParser
from os.path import splitext

parser = ArgumentParser(description='Compile a Redux script to Rescript.')
parser.add_argument('input_filename', metavar='FILE',
                    help='script to be compiled to Rescript')
parser.add_argument('output_filename', metavar='FILE',
                    help='script to be compiled to Rescript')

args = parser.parse_args()

filename = args.input_filename
assert filename, "no input file given"

with open(filename, "rt") as file_:
    input_code = file_.read()

output_code = compile_script(filename, input_code)

base_filename, extension = splitext(filename)
with open(args.output_filename, "wt") as file_:
    file_.write(output_code)
