"""
|**********************************************************************;
* Project           : VYPcode compiler 2019
* Authors           : Michal Horky (xhorky23), Matus Mucka (xmucka03)
|**********************************************************************;
"""
import sys

from src.instructionsTape import MAIN_INSTRUCTION_TAPE


class Printer:
    def __init__(self, file):
        self.file = file

    def error(self, s):
        print(str(s), file=sys.stderr)

    def close(self):
        if self.file:
            self.file.close()

    def _print(self, output_file):
        output_file.write(
            '#!/bin/vypint\n' +
            '# VYPcode: 1.0\n' +
            '# Generated by: xhorky23 xmucka03\n'
        )
        for instrunction in MAIN_INSTRUCTION_TAPE.get_instructions():
            output_file.write(str(instrunction) + '\n')

    def print(self):
        with open(self.file, 'x', encoding="utf-8") as output_file:
            self._print(output_file)


Output = Printer(sys.argv[2] if len(sys.argv) > 2 else "out.vc")
