24 lines
666 B
TypeScript
24 lines
666 B
TypeScript
import { Vm } from "../vm";
|
|
import { TextPiece } from "../words";
|
|
import { getOpt } from "./options";
|
|
|
|
/**
|
|
* Basic unit of information, also an "actor" in the programming system
|
|
*/
|
|
export type Card = {
|
|
/** Unique identifier */
|
|
id: number;
|
|
/** Key-value properties on the card */
|
|
fields: Record<string, string>;
|
|
/** Eventually: a markdown string containing code, but for now, just code */
|
|
code: string;
|
|
};
|
|
|
|
export type CardVm = Vm<{
|
|
card: Card;
|
|
}>;
|
|
|
|
export function GetField(vm: CardVm, argv: TextPiece[]): TextPiece {
|
|
const [{ error }, fieldName] = getOpt(argv, { $min: 1, $max: 1 });
|
|
return { text: vm.card.fields[fieldName] ?? error ?? "" };
|
|
}
|