From 562bc94f9b48947e1b64e2eab08919f1f99f7fa9 Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 22 Dec 2021 08:35:48 -0500 Subject: [PATCH] proper argument typings. devMode ON --- .system | 3 ++- src/commands/save.ts | 7 +++--- src/externals.d.ts | 2 ++ src/index.ts | 34 +++++++++++++++++++++++------- src/modules/n-arm-bandit/bandit.ts | 1 + 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/.system b/.system index 00da811..b2f1369 100644 --- a/.system +++ b/.system @@ -55,5 +55,6 @@ "SLOT3": "0F0B6AEB69754319A7E480E3989F7E54", "SLOT4": "34064741B6324D9BBCEE0A1364F21220", "SLOT5": "18461538E5A1487EBC9F54040295440A" - } + }, + "devMode": true } \ No newline at end of file diff --git a/src/commands/save.ts b/src/commands/save.ts index 0603984..681dec3 100644 --- a/src/commands/save.ts +++ b/src/commands/save.ts @@ -1,13 +1,14 @@ -import { system } from '@kernel:base'; +import { system, ParsedSystemState } from '@kernel:base'; import { resolve } from 'path'; import { writeFileSync } from 'fs'; export default function save() { const timeStart = new Date().getTime(); - const obj: any = { + const obj: ParsedSystemState = { handoff: system.handoff, instances: {}, - aliases: {} + aliases: {}, + devMode: system.devMode }; for(const [id, info] of system.instances.entries()) { obj.instances[id] = { diff --git a/src/externals.d.ts b/src/externals.d.ts index 5eee178..b6089e3 100644 --- a/src/externals.d.ts +++ b/src/externals.d.ts @@ -17,6 +17,7 @@ declare module "@kernel:base" { type Id = string; type ParsedSystemState = { handoff: string, + devMode: boolean, instances: { [id: Id]: { config: any, @@ -31,6 +32,7 @@ declare module "@kernel:base" { aliases: Map; instances: Map; handoff: string; + devMode: boolean; } const system: System; } diff --git a/src/index.ts b/src/index.ts index 279e0e5..98a2994 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ /// -import { Instance, ParsedSystemState } from '@kernel:base'; +import { Instance, ParsedSystemState, System } from '@kernel:base'; import '@kernel:log-hook'; import createExecutor from '@commands:executor'; import create from '@commands:create'; @@ -17,12 +17,11 @@ import md5 from 'md5'; const args = process.argv.slice(2); const [ startupFile ] = args; -export type Id = string; - -export const system = { +export const system: System = { instances: new Map(), handoff: '', - aliases: new Map() + aliases: new Map(), + devMode: false } export function reverseAliasMap() { @@ -47,7 +46,22 @@ export function autoColorString(string: string) { export const exec = async (s: string, echo = true) => { if(echo) console.log(chalk.cyan('@ ') + chalk.ansi256(242)(s)); - await executor(...(s.split(' '))); + + const args: (string | number | boolean)[] = []; + for(const arg of s.split(' ')) { + const asNum = parseFloat(arg); + const isTrue = arg.toLowerCase() === 'true'; + const isBoolean = isTrue || arg.toLowerCase() === 'false'; + if(isBoolean) { + args.push(isTrue); + } else if(!isNaN(asNum)) { + args.push(asNum) + } else { + args.push(arg); + } + } + + await executor(...args); }; export const kernel = { @@ -87,8 +101,12 @@ export const kernel = { await exec(line); } }, - set(variable: string, ...rest: string[]) { - (system as any)[variable] = rest.join(' '); + set(variable: string, ...rest: any) { + if(rest.length > 1) { + (system as any)[variable] = rest.join(' '); + } else { + (system as any)[variable] = rest[0]; + } }, help: help }; diff --git a/src/modules/n-arm-bandit/bandit.ts b/src/modules/n-arm-bandit/bandit.ts index 364d113..161c525 100644 --- a/src/modules/n-arm-bandit/bandit.ts +++ b/src/modules/n-arm-bandit/bandit.ts @@ -13,6 +13,7 @@ function randomNormal(width: number = 1, offset: number = 0) { while(u === 0) u = Math.random(); //Converting [0,1) to (0,1) while(v === 0) v = Math.random(); const base = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v ); + return offset + base * width; } export function pull() {