handoff & invoke respected
parent
67a9a9715d
commit
8c6ad8a72b
11
.system
11
.system
|
|
@ -1,17 +1,14 @@
|
||||||
{
|
{
|
||||||
"handoff": "",
|
"handoff": "invoke systemd boot",
|
||||||
"instances": {
|
"instances": {
|
||||||
"50C60F4EF04D41B38A2EB573788829DA": {
|
"B7FFCD6C11974FC7A74509B6683D7420": {
|
||||||
"config": {},
|
"config": {},
|
||||||
"module": "systemd"
|
"module": "systemd"
|
||||||
},
|
},
|
||||||
"C34D0DE00AB3454195E9249BF3596610": {
|
"600F5B3828BC4D78BCBA375596F6898B": {
|
||||||
"config": {},
|
"config": {},
|
||||||
"module": "sshd"
|
"module": "sshd"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"aliases": {
|
"aliases": {}
|
||||||
"systemd": "50C60F4EF04D41B38A2EB573788829DA",
|
|
||||||
"sshd": "C34D0DE00AB3454195E9249BF3596610"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,10 @@ export default async function create(module: string, name: string, id: string) {
|
||||||
if(name && (typeof name !== 'string' || name.trim() === '')) {
|
if(name && (typeof name !== 'string' || name.trim() === '')) {
|
||||||
throw new Error('IVALID_MODULE_ALIAS');
|
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(system.aliases.has(name)) {
|
||||||
if(name === module) {
|
if(name === module) {
|
||||||
throw new Error('DEFAULT_MODULE_ALREADY_EXISTS');
|
throw new Error('DEFAULT_MODULE_ALREADY_EXISTS');
|
||||||
|
|
|
||||||
36
src/index.ts
36
src/index.ts
|
|
@ -54,14 +54,26 @@ export const kernel = {
|
||||||
ls: ls,
|
ls: ls,
|
||||||
save: save,
|
save: save,
|
||||||
reset() {
|
reset() {
|
||||||
|
// TODO add a user interaction requirement here... its kindof rm -rf...
|
||||||
system.handoff = '';
|
system.handoff = '';
|
||||||
system.instances = new Map();
|
system.instances = new Map();
|
||||||
system.aliases = new Map();
|
system.aliases = new Map();
|
||||||
console.log('System has been reset.');
|
console.log('System has been reset.');
|
||||||
},
|
},
|
||||||
exec: exec,
|
exec: exec,
|
||||||
invoke(...a: any[]) {
|
async invoke(location: string, fn: string, ...args: string[]) {
|
||||||
console.log(a);
|
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) {
|
async script(path: string) {
|
||||||
const fullPath = resolve(path);
|
const fullPath = resolve(path);
|
||||||
|
|
@ -69,6 +81,9 @@ export const kernel = {
|
||||||
for(const line of lines) {
|
for(const line of lines) {
|
||||||
await exec(line);
|
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);
|
await exec('script ' + startupFile);
|
||||||
checkpoint('Script Finished');
|
checkpoint('Script Finished');
|
||||||
await exec('quit');
|
await exec('quit');
|
||||||
} else {
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
serverline.init({
|
await exec(system.handoff);
|
||||||
prompt: chalk.cyan('λ ')
|
checkpoint('Handoff Finished');
|
||||||
});
|
|
||||||
|
serverline.init({ prompt: chalk.cyan('λ ') });
|
||||||
serverline.setCompletion(Object.keys(kernel));
|
serverline.setCompletion(Object.keys(kernel));
|
||||||
serverline.on('line', (a: string) => {
|
serverline.on('line', (a: string) => {
|
||||||
if(a.trim() === "") return;
|
if(a.trim() === "") return;
|
||||||
exec(a, false);
|
exec(a, false);
|
||||||
});
|
});
|
||||||
|
serverline.on('SIGINT', () => exec('quit'));
|
||||||
serverline.on('SIGINT', () => {
|
|
||||||
exec('quit');
|
|
||||||
});
|
|
||||||
|
|
||||||
})().catch((e: Error) => {
|
})().catch((e: Error) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
checkpoint('Kernel Loaded');
|
checkpoint('Kernel Loaded');
|
||||||
import '@echo off';
|
import '@echo off';
|
||||||
Loading…
Reference in New Issue