Create a CLI with Brocli
mainBrocli is a type-safe way to build CLIs using TypeScript or JavaScript. You define commands using the command function, specify their options (including validation and defaults), and provide a handler function to execute the business logic. Finally, use run() to parse shell arguments and execute the commands.
To use Brocli, import the necessary primitives from @drizzle-team/brocli and pass an array of command objects to run().
import { command, string, boolean, run } from "@drizzle-team/brocli";
const push = command({
name: "push",
options: {
dialect: string().enum("postgresql", "mysql", "sqlite"),
databaseSchema: string().required(),
databaseUrl: string().required(),
strict: boolean().default(false),
},
handler: (opts) => {
// Business logic using typed opts
},
});
run([push]);