npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zoltra/cli-builder

v0.1.2

Published

A fast and lightweight CLI builder for TypeScript applications

Downloads

14

Readme

Zoltra CLI Builder

A fast and lightweight CLI builder for TypeScript applications with excellent performance and developer experience.

Features

  • 🚀 Fast: Optimized parsing with caching for high performance
  • 🎯 TypeScript: Full TypeScript support with type safety
  • 🛠️ Flexible: Support for commands, options, arguments, and subcommands
  • 🎨 Beautiful: Colored output with chalk integration
  • 📚 Help System: Auto-generated help and usage information
  • 🔧 Extensible: Easy to extend and customize

Installation

npm install @zoltra/cli-builder

Quick Start

import { createCLI } from "@zoltra/cli-builder";

const cli = createCLI("myapp", "1.0.0", "My awesome CLI app");

// Add global options
cli.option("verbose", "Enable verbose output", { alias: "v", type: "boolean" });

// Add commands
cli
  .command("greet", "Greet someone")
  .argument("name", "Name to greet", { required: true })
  .option("style", "Greeting style", {
    choices: ["formal", "casual"],
    default: "casual",
  })
  .action(async (args, options) => {
    const greeting = options.style === "formal" ? "Hello" : "Hey";
    console.log(`${greeting}, ${args[0]}!`);
  })
  .finalize();

// Parse and run
cli.parse();

Usage

Basic Commands

# Show help
myapp --help

# Run a command
myapp greet "World"

# Use options
myapp greet "World" --style formal

# Use short options
myapp greet "World" -v

Command Definition

cli
  .command("build", "Build the project")
  .option("output", "Output directory", {
    alias: "o",
    type: "string",
    default: "./dist",
  })
  .option("watch", "Watch for changes", {
    alias: "w",
    type: "boolean",
  })
  .argument("source", "Source directory", {
    required: true,
  })
  .action(async (args, options) => {
    console.log(`Building from ${args[0]} to ${options.output}`);
    if (options.watch) {
      console.log("Watching for changes...");
    }
  });

Option Types

  • boolean: True/false flags
  • string: Text values
  • number: Numeric values
  • array: Comma-separated values

Global Options

cli.option("config", "Path to config file", {
  type: "string",
  default: "./config.json",
});

Subcommands

const deployCmd = cli.command("deploy", "Deploy the application");

deployCmd.command("staging", "Deploy to staging").action(async () => {
  console.log("Deploying to staging...");
});

deployCmd
  .command("production", "Deploy to production")
  .option("confirm", "Skip confirmation", { type: "boolean" })
  .action(async (args, options) => {
    if (!options.confirm) {
      // Ask for confirmation
    }
    console.log("Deploying to production...");
  });

API Reference

createCLI(name, version, description?)

Creates a new CLI instance.

  • name: CLI name
  • version: CLI version
  • description?: Optional description

CLI Methods

.command(name, description)

Add a new command.

.option(name, description, config?)

Add a global option.

.action(handler)

Set the default action.

.parse(argv?)

Parse command line arguments and execute.

Command Builder Methods

.alias(alias)

Add an alias for the command.

.option(name, description, config?)

Add an option to the command.

.argument(name, description, config?)

Add an argument to the command.

.action(handler)

Set the command action.

.command(name, description)

Add a subcommand.

finalize()

Adds the current command to its parent builder

Advanced Usage

Custom Validation

cli
  .command("create", "Create a new item")
  .argument("type", "Item type", {
    required: true,
    // Custom validation can be added here
  })
  .action(async (args) => {
    const [type] = args;
    // Your logic here
  });

Async Actions

All actions support async/await:

cli.command("fetch", "Fetch data").action(async (args, options) => {
  const data = await fetchData();
  console.log(data);
});

Error Handling

The CLI automatically handles errors and displays them with colored output:

cli.command("dangerous", "A dangerous command").action(async () => {
  throw new Error("Something went wrong!");
});

Performance

Fast CLI Builder is optimized for performance:

  • Regex caching: Pre-compiled regular expressions
  • Option caching: Cached option lookups to avoid repeated searches
  • Lazy evaluation: Options are only parsed when needed
  • Minimal dependencies: Small bundle size

Examples

See the examples/ directory for more usage examples:

  • Basic CLI
  • Multi-command CLI
  • Interactive CLI
  • Configuration management

Contributing

Contributions are welcome! Please see the contributing guidelines.

License

MIT