#! /usr/bin/env python

#
# Copyright (C) 2014-2022, AdaCore
# SPDX-License-Identifier: Apache-2.0
#

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import argparse

from IPython import embed
from IPython.terminal.ipapp import load_default_config



import libadalang
import libadalang as lal


HEADER = """
--
-- libadalang playground
--

The file(s) passed as argument have been put into the u variable, or units if
there are multiple.

Enjoy!
""".strip()

class Playground(libadalang.App):

    def add_arguments(self):
        self.parser.add_argument(
            '-i', '--input-script', type=str, default='',
            help="Script to execute when playground has loaded the units"
        )
        super(Playground, self).add_arguments()

    def main(self):
        print(HEADER)
        c = load_default_config()

        if self.args.input_script:
            execfile(self.args.input_script)

        # Put useful values in local variables, so that they're easily
        # accessible from embed.
        units = self.units
        ctx = self.ctx
        u = self.u

        embed(header=HEADER, config=c, display_banner=False)


if __name__ == '__main__':
    Playground.run()
