From 2af211f1bd6a5c81ee7acd2ded2bfacf4dcfb2a4 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Mon, 9 Jan 2023 19:38:28 +0530 Subject: feat: cli donezy --- src/index.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 65349fc..01420c8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,27 @@ +import { program } from 'commander' import { createContext } from './context' -import { evalList } from './eval' - -const main = async () => { - const ctx = createContext() - const resultType = ctx.entryPoint.getType() - const effects = resultType.isTuple() - ? resultType.getTupleElements() - : [resultType] - await evalList(ctx, effects) +import { cleanup, evalList } from './eval' + +const main = () => { + program + .name('ts-types-lang') + .description(`A runtime for typescript's type system that turns it into a general purpose, purely functional programming language!`) + + program + .command('run') + .description('Run a typescript .ts file') + .argument('', 'Typescript file to run') + .action(async (filePath) => { + const ctx = createContext({ filePath }) + const resultType = ctx.entryPoint.getType() + const effects = resultType.isTuple() + ? resultType.getTupleElements() + : [resultType] + await evalList(ctx, effects) + }) + + return program.parseAsync() } main() - .then(() => process.exit(0)) - .catch((e) => (console.error(e), process.exit(1))) + .finally(() => cleanup()) -- cgit v1.3.1