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)

Install

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

Example

import { CLI, withColorPlugin } from 'https://deno.land/x/spektr/mod.ts'

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

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)