Skip to content

StauroDEV/spektr

Repository files navigation

Spektr

npm GitHub Workflow Status Coverage

Elegant CLI framework. Inspired by cac. Works with Deno, Node.js and Bun.

Features

  • Infinite nesting for commands (aka git remote add)
  • Default command support
  • Automatic help/version, including individual commands and programs
  • Argument validation
  • Auto-complete for options
  • Pluggable (color plugin out-of-the-box)
  • Middleware API to run before commands

Install

# Bun
bun i spektr
# pnpm
pnpm i spektr
# Deno
echo "export { CLI } from 'https://deno.land/x/spektr/spektr.ts'" >> deps.ts

Example

import { CLI } from 'https://deno.land/x/spektr/spektr.ts'
import { colorPlugin } from 'https://deno.land/x/spektr/spektr/plugins/color.ts'

const cli = new CLI({ name: 'spektr', plugins: [colorPlugin] })

cli.command(
  'hello',
  (_, args) => {
    args.name ? console.log(`Hello ${args.name}!`) : console.log('Hello!')
  },
  {
    options: [
      { name: 'name', description: 'your name', type: 'string', short: ['n'] },
    ] as const,
  },
)

cli.version()

cli.help()

cli.handle(Deno.args)