Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Latest commit

 

History

History
134 lines (100 loc) · 2.71 KB

File metadata and controls

134 lines (100 loc) · 2.71 KB

@funish/cli

npm version npm downloads npm license Contributor Covenant

A powerful CLI framework for building command line applications, powered by Funish.

Features

  • 🚀 Simple and intuitive API
  • 📦 Automatic package.json metadata integration
  • 🎯 Type-safe command definitions
  • 🔄 Nested subcommands support
  • ⚙️ Automatic help generation
  • 🎨 Beautiful command-line output
  • 💪 Built on top of citty
  • 🌟 Full TypeScript support

Installation

# npm
$ npm install @funish/cli

# yarn
$ yarn add @funish/cli

# pnpm
$ pnpm add @funish/cli

Usage

Basic Command

import { defineCommand } from "@funish/cli";

const cmd = defineCommand({
  meta: {
    name: "greet",
  },
  args: {
    name: {
      type: "string",
      description: "Name to greet",
      required: true,
    },
  },
  run: (ctx) => {
    console.log(`Hello, ${ctx.args.name}!`);
  },
});

With Subcommands

const cmd = defineCommand({
  meta: {
    name: "app",
  },
  subCommands: {
    serve: {
      args: {
        port: {
          type: "number",
          default: 3000,
        },
      },
      run: (ctx) => {
        console.log(`Starting server on port ${ctx.args.port}`);
      },
    },
  },
});

Automatic Metadata

The defineCommand function automatically reads metadata from your package.json:

const cmd = defineCommand({
  // No need to specify name, version, or description
  // They are automatically loaded from package.json
  args: {
    // ...
  },
  run: (ctx) => {
    // ...
  },
});

API Reference

defineCommand(def)

Creates a command definition with automatic metadata from package.json.

Parameters

  • def (CommandDef): Command definition object
    • meta?: Command metadata
    • args?: Command arguments definition
    • subCommands?: Nested subcommands
    • run: Command execution function

Returns

Returns an enhanced command definition with metadata from package.json.

readPackageJSON(path?)

Reads the nearest package.json file.

Parameters

  • path (string, optional): Starting directory path (defaults to current script directory)

Returns

Returns the parsed package.json content or an empty object if not found.

Contributing

Please read our Contributing Guide before submitting a Pull Request to the project.

License

MIT © Funish