expose getOpt error handling to frontend

This commit is contained in:
Tangent Wantwight 2023-10-20 18:22:08 -04:00
parent 594d81b745
commit 6196f6c4aa
3 changed files with 11 additions and 15 deletions

3
TODO
View file

@ -1,9 +1,6 @@
- path to event listener:
- card fields (vars maybe not needed yet?)
- get field command
- current card in state
- command
- set field command
- formatter helper for debug page
- unit test

View file

@ -1,8 +1,8 @@
import { Card, CardVm, GetField } from './lib/card';
import { ALL as HTML } from './lib/html';
import { parse } from './parser';
import { runNoctl, Vm } from './vm';
import { AsHtml, AsText, TextPiece } from './words';
import { Card, CardVm, GetField } from "./lib/card";
import { ALL as HTML } from "./lib/html";
import { parse } from "./parser";
import { runNoctl, Vm } from "./vm";
import { AsHtml, AsText, TextPiece } from "./words";
/**
* Updates a card's fields
@ -65,7 +65,7 @@ title "Hello, World!"
const codeInput = document.createElement("textarea");
Object.assign(codeInput.style, TEXTAREA_STYLE, { height: "20em" });
codeInput.value = String.raw`
h1 "Hello, World!"
h1 [get title]
para [2 + 2]
block {
This is a paragraph of text, with one [b bold] word. Yes, this means there has to be some magic in text processing... <b>this</b> won't work.

View file

@ -1,6 +1,6 @@
import { Vm } from '../vm';
import { TextPiece } from '../words';
import { getOpt } from './options';
import { Vm } from "../vm";
import { TextPiece } from "../words";
import { getOpt } from "./options";
/**
* Basic unit of information, also an "actor" in the programming system
@ -19,7 +19,6 @@ export type CardVm = Vm<{
}>;
export function GetField(vm: CardVm, argv: TextPiece[]): TextPiece {
const [{ error = false }, fieldName] = getOpt(argv, { min: 1, max: 1 });
// TODO: handle error
return { text: vm.card.fields[fieldName] ?? "" };
const [{ error }, fieldName] = getOpt(argv, { $min: 1, $max: 1 });
return { text: vm.card.fields[fieldName] ?? error ?? "" };
}