diff --git a/.system b/.system index 76bd100..c97c966 100644 --- a/.system +++ b/.system @@ -1,17 +1,14 @@ { - "handoff": "", + "handoff": "invoke systemd boot", "instances": { - "50C60F4EF04D41B38A2EB573788829DA": { + "B7FFCD6C11974FC7A74509B6683D7420": { "config": {}, "module": "systemd" }, - "C34D0DE00AB3454195E9249BF3596610": { + "600F5B3828BC4D78BCBA375596F6898B": { "config": {}, "module": "sshd" } }, - "aliases": { - "systemd": "50C60F4EF04D41B38A2EB573788829DA", - "sshd": "C34D0DE00AB3454195E9249BF3596610" - } + "aliases": {} } \ No newline at end of file diff --git a/src/commands/create.ts b/src/commands/create.ts index ac91ab3..707358f 100644 --- a/src/commands/create.ts +++ b/src/commands/create.ts @@ -8,7 +8,10 @@ export default async function create(module: string, name: string, id: string) { if(name && (typeof name !== 'string' || name.trim() === '')) { throw new Error('IVALID_MODULE_ALIAS'); } - name ??= module; + // undefined means no paramter given. this is treated as a default alias + // otherise, null should be to create anonymous instances. only addressable + // by their creator or by discovery protocols to come soon... + name = name === undefined ? module : null; if(system.aliases.has(name)) { if(name === module) { throw new Error('DEFAULT_MODULE_ALREADY_EXISTS'); diff --git a/src/index.ts b/src/index.ts index 75de3d7..0ef76da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,14 +54,26 @@ export const kernel = { ls: ls, save: save, reset() { + // TODO add a user interaction requirement here... its kindof rm -rf... system.handoff = ''; system.instances = new Map(); system.aliases = new Map(); console.log('System has been reset.'); }, exec: exec, - invoke(...a: any[]) { - console.log(a); + async invoke(location: string, fn: string, ...args: string[]) { + if(system.aliases.has(location)) { + location = system.aliases.get(location); + } + if(!system.instances.has(location)) { + throw new Error('INVOCATION_TARGET_DOES_NOT_EXIST'); + } + const instance = system.instances.get(location); + if(!(fn in instance.functions)) { + throw new Error('FUNCTION_DOES_NOT_EXIST_ON_INVOCATION_TARGET'); + } + const bound = instance.functions[fn].bind(instance); + await bound(...args); }, async script(path: string) { const fullPath = resolve(path); @@ -69,6 +81,9 @@ export const kernel = { for(const line of lines) { await exec(line); } + }, + set(variable: string, ...rest: string[]) { + (system as any)[variable] = rest.join(' '); } }; @@ -94,24 +109,23 @@ const executor = createExecutor(kernel); await exec('script ' + startupFile); checkpoint('Script Finished'); await exec('quit'); - } else { + return; } - serverline.init({ - prompt: chalk.cyan('λ ') - }); + await exec(system.handoff); + checkpoint('Handoff Finished'); + + serverline.init({ prompt: chalk.cyan('λ ') }); serverline.setCompletion(Object.keys(kernel)); serverline.on('line', (a: string) => { if(a.trim() === "") return; exec(a, false); }); - - serverline.on('SIGINT', () => { - exec('quit'); - }); + serverline.on('SIGINT', () => exec('quit')); })().catch((e: Error) => { console.error(e); }); + checkpoint('Kernel Loaded'); -import '@echo off'; +import '@echo off'; \ No newline at end of file