#!/usr/bin/env python3
# -*- Python -*-
# -*- coding: utf-8 -*-
#
# michael a.g. aïvázis
# orthologue
# (c) 1998-2023 all rights reserved
#

# support
import pyre

# the app
class Config(pyre.application):

    # information the user can ask for
    version = pyre.properties.bool(default=False)
    version.doc = "the framework version"

    prefix = pyre.properties.bool(default=False)
    prefix.doc = "the top level installation directory"

    path = pyre.properties.bool(default=False)
    path.doc = "the directory with the built in scripts"

    ldpath = pyre.properties.bool(default=False)
    ldpath.doc = "the directory with the shared libraries"

    pythonpath = pyre.properties.bool(default=False)
    pythonpath.doc = "the directory with the python packages"

    includes = pyre.properties.bool(default=False)
    includes.doc = "compiler access to the headers"

    libs = pyre.properties.bool(default=False)
    libs.doc = "compiler link line"


    # the main entry point
    @pyre.export
    def main(self, *args, **kwds):
        """
        Print pyre configuration information
        """
        # do we need to show the help screen
        help = True
        # get the package layout
        layout = pyre.packageInfo()

        # if we were asked to show the framework version
        if self.version:
            # get the version
            major, minor, micro, rev = pyre.version()
            # do it
            print(f"{major}.{minor}.{micro}")
            # and lower the flag
            help = False

        # if we were asked to show the installation directory
        if self.prefix:
            # do it
            print(layout["prefix"])
            # and lower the flag
            help = False

        # if we were asked to show the directory with the built in scripts
        if self.path:
            # do it
            print(layout["path"])
            # and lower the flag
            help = False

        # if we were asked to show the directory with the shared libraries
        if self.ldpath:
            # do it
            print(layout["ldpath"])
            # and lower the flag
            help = False

        # if we were asked to show the directory with the python packages
        if self.pythonpath:
            # do it
            print(layout["pythonpath"])
            # and lower the flag
            help = False

        # if we were asked to build a compiler command line for accessing the headers
        if self.includes:
            # do it
            print(layout["includes"])
            # and lower the flag
            help = False

        # if were asked to build a link line
        if self.libs:
            # do it
            print(layout["libs"])
            # and lower the flag
            help = False

        # if we weren't asked to do anything
        if help:
            # show the help screen
            return self.help()

        # all done
        return 0


# main
if __name__ == '__main__':
    # instantiate
    app = Config(name='pyre-config')
    # invoke
    status = app.run()
    # and share the status code
    raise SystemExit(status)


# end of file
