all repos — momix @ 80d4b3b7c8b41c2a3cb66d9f63dbb839173da148

A CLI tool to manage recipes for Thermomix

commands/grocery.ts (view raw)

 1import type { DatabaseSync } from "node:sqlite";
 2import { Checkbox } from "@cliffy/prompt";
 3import { Table } from "@cliffy/table";
 4import { getGroceryList, getRecipesList } from "../services.ts";
 5
 6export default async (db: DatabaseSync) => {
 7  const recipes = getRecipesList(db);
 8
 9  const choices = await Checkbox.prompt({
10    message: "Select recipes",
11    options: recipes.map((recipe) => ({
12      name: recipe.name as string,
13      value: recipe.id,
14    })),
15  });
16
17  const ingredients = getGroceryList(db, choices as number[]);
18
19  const table = new Table(
20    ...ingredients.map((item) => [item.name, item.quantity, item.unit])
21  ).header(["Name", "Quantity", "Unit"]);
22
23  console.log(table.border().sort().toString());
24};