How widgets and connectors work together
mainTermost uses a fluent interface to build CLI tools. You initialize a program using termost<T>(), where T is your ProgramContext type. You then chain instructions like .option(), .command(), .input(), and .task() to define the CLI behavior.
Key concepts:
- Context: A shared object that persists values across instructions. Values are stored using the
keyprovided in options, inputs, or tasks. - Subcommands: Created via
.command(). Subcommands have their own scoped context, but they can access the root command's context. - Tasks: The execution units of your CLI. They can perform side effects or return values that are persisted into the context if a
keyis provided. - Instructions: Each method call (
option,input,task) adds a step to the CLI lifecycle.
const program = termost<ProgramContext>({
name: 'my-cli',
description: 'CLI description',
version: '1.0.0',
});
program
.option({ key: 'flag', name: 'f', description: 'desc' })
.task({ handler: () => {} });