#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# ----------------------------------------------------------------------
# Copyright 2019 Airinnova AB and the FramAT authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------

# Author: Aaron Dettmann

"""
FEMAD

3D finite element analysis
"""

import argparse

from framat.stdfun import standard_run, clean_project_dir, __prog_name__
from framat.__version__ import __version__
from framat.fileio.utils import FileStructure


def cmd_interface():
    """
    Run FramAT using a command line interface
    """

    # ===== Arguments =====
    parser = argparse.ArgumentParser(prog=f'{__prog_name__} {__version__}')

    parser.add_argument("filename", help="Input file", type=str)
    parser.add_argument("--no-schema-check", action="store_false")

    group = parser.add_mutually_exclusive_group()
    group.add_argument("-v", "--verbose", action="store_true")
    group.add_argument("-d", "--debug", action="store_true")
    group.add_argument("-q", "--quiet", action="store_true")

    group = parser.add_mutually_exclusive_group()
    group.add_argument("-c", "--clean", help="remove old project files", action="store_true")
    group.add_argument("--clean-only", help="clean and exit", action="store_true")

    args = parser.parse_args()

    if any((args.clean, args.clean_only)):
        clean_project_dir(FileStructure(args.filename))

        if args.clean_only:
            return

    standard_run(args)


if __name__ == '__main__':
    cmd_interface()
