import os, yaml

from ..utils.logger import show_help 
from ..utils.context import Context
from ..utils.utils import check_project

def build():
  config = Context.config
  root_path = Context.root_path
  args = Context.command['args']

  check_project(args)

  global inner_config
  app_relative_path = os.path.join(root_path, config['services'][args]['path'])
  try:
    with open(os.path.join(app_relative_path, 'reqs.yaml'), 'r') as stream:
      inner_config = yaml.safe_load(stream)
    os.system(
      f"cd {app_relative_path}\n{inner_config['scripts']['build']}"
    )
  except ResourceWarning as e:
    print(e)

def help():
  show_help(
    command='build',
    description='Executes the build script for the project.',
    usage=[
      {
        'command': 'build',
        'description': 'Executes the build script in your reqs.yaml file.'
      },
    ]
  )