choose

tcmts.cli.ui.choose · #izxs6cez · term · runs on the server

uses @clack/prompts's exports, which uses node:fs

What usage describes, asked for if a person can be: message, choosing from options.

import { answer, interactive, UsageError } from "#codebase/tcmts/cli/ui";
import * as p from "@clack/prompts";

export async function choose<T>(usage: string, message: string, options: { value: T; label: string; hint?: string }[], search = options.length > 8): Promise<T> {
  if (!interactive()) throw new UsageError(`usage: tcm ${usage}`);
  if (!options.length) throw new UsageError(`nothing to choose from (usage: tcm ${usage})`);
  const asked = search ? p.autocomplete<T>({ message, options: options as never, placeholder: "type to search", maxItems: 12 }) : p.select<T>({ message, options: options as never });
  return answer<T>(await asked);
}

uses

used by