from importlib.metadata import metadata
import os
import json
import os
from easyspec_mods.cli import *


# Scope connector allows passing some variables by reference to Python's interactable mode environment.
scope_connector = {
                    'selected_module':{},
                    'modules':{},
                    'help':{},
                }

def main():
    fullscreen()   
    load_meta_file('modules')
    load_meta_file('help')
    enter_easyspec_cli(globals())
    
def modules():
    cls()
    global scope_connector
    display_modules(scope_connector['modules'])
    module_selection(globals())
globals()['m'] = modules

def help():
    cls()
    global scope_connector
    display_help(scope_connector['help'])
globals()['h'] = help

def procedures():
    cls()
    print_procedures(globals())
globals()['p'] = procedures

# The package map file (modules.json) is created during the build and placed in the first-level modules directory.
# It maps all the modules composing the package, giving the name, current version and description.
def load_meta_file(meta_file_name):
    modules_path = os.path.join(os.path.dirname(__file__), f"{meta_file_name}.json")
    with open(modules_path, 'r') as f:
        global scope_connector
        scope_connector[f"{meta_file_name}"] = json.load(f)