import json
import os
import sys
from colored import stylize, fg
process_id: int = os.getpid()
user: os.uname_result = os.uname()
filename = 'forgefile.json'
initialize_command_key = '.init'
with open(filename) as infile:
contents = json.load(infile)
initialize_commands = contents.get(initialize_command_key, None)
combined_commands: str = ''
if initialize_commands:
for command in initialize_commands:
combined_commands += f'{command}; '
print(stylize(f'{user.nodename}@{user.sysname}:~$ ', fg('green')), end='')
command_to_execute = input()
split_commands: list = command_to_execute.split(' ')
if not split_commands:
raise Exception('No command provided')
if split_commands[0] != 'forge':
raise Exception('Invalid command')
sub_command: str = ' '.join(split_commands[1:])
sub_commands_to_execute: list | None = contents.get(sub_command, None)
if not sub_commands_to_execute:
command: str = f'{combined_commands}{sub_command}'
os.system(command)
sys.exit(1)
for sub_command in sub_commands_to_execute:
os.system(f'{combined_commands}{sub_command}')