{"name":"citty","version":"0.2.0","license":"MIT","_id":"citty@0.2.0","maintainers":[{"name":"pi0","email":"pyapar@gmail.com"}],"homepage":"https://github.com/unjs/citty#readme","bugs":{"url":"https://github.com/unjs/citty/issues"},"dist":{"shasum":"2426b145c4bf2a2c5c33bd66a634dfe3d5ea67ea","tarball":"http://registry-npm.ywwl.com/citty/download/citty-0.2.0.tgz","fileCount":6,"integrity":"sha512-8csy5IBFI2ex2hTVpaHN2j+LNE199AgiI7y4dMintrr8i0lQiFn+0AWMZrWdHKIgMOer65f8IThysYhoReqjWA==","signatures":[{"sig":"MEUCIAwr0wkJeaD73QU8ubkkdYs/x2rP9Ccty0B3CLCn9KuJAiEAzaiAA51X8sBF+nKOoWF45O5fecsF6UTHmTbj/TuuKTY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23363,"size":7645,"noattachment":false,"key":"/citty/-/citty-0.2.0.tgz"},"type":"module","types":"./dist/index.d.mts","exports":{".":"./dist/index.mjs"},"gitHead":"97d89f962f8b10ce7411e24831636873f4b93422","scripts":{"dev":"vitest dev","lint":"eslint --cache . && prettier -c src test","play":"node ./playground/cli.ts","test":"pnpm lint && pnpm test:types && vitest run --coverage","build":"obuild","prepack":"pnpm run build","release":"pnpm test && pnpm build && changelogen --release --push && npm publish","lint:fix":"eslint --cache . --fix && prettier -c src test -w","test:types":"tsc --noEmit"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"repository":{"url":"git+https://github.com/unjs/citty.git","type":"git"},"_npmVersion":"11.6.2","description":"Elegant CLI Builder","directories":{},"sideEffects":false,"_nodeVersion":"24.11.1","_hasShrinkwrap":false,"packageManager":"pnpm@10.28.1","devDependencies":{"scule":"^1.3.0","automd":"^0.4.2","eslint":"^9.39.2","obuild":"^0.4.18","vitest":"^4.0.17","prettier":"^3.8.0","typescript":"^5.9.3","@types/node":"^25.0.9","changelogen":"^0.6.2","eslint-config-unjs":"^0.6.2","@vitest/coverage-v8":"^4.0.17"},"_npmOperationalInternal":{"tmp":"tmp/citty_0.2.0_1768909783457_0.6679400314766557","host":"s3://npm-registry-packages-npm-production"},"readme":"# 🌆 citty\n\n<!-- automd:badges color=yellow bundlephobia -->\n\n[![npm version](https://img.shields.io/npm/v/citty?color=yellow)](https://npmjs.com/package/citty)\n[![npm downloads](https://img.shields.io/npm/dm/citty?color=yellow)](https://npmjs.com/package/citty)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/citty?color=yellow)](https://bundlephobia.com/package/citty)\n\n<!-- /automd -->\n\nElegant CLI Builder\n\n- Zero dependency, fast and lightweight (based on native [`util.parseArgs`](https://nodejs.org/api/util.html#utilparseargsconfig))\n- Smart value parsing with typecast and boolean shortcuts\n- Nested sub-commands with lazy and async loading\n- Pluggable and composable API with auto generated usage\n\n## Usage\n\n```sh\nnpx nypm add -D citty\n```\n\n```js\nimport { defineCommand, runMain } from \"citty\";\n\nconst main = defineCommand({\n  meta: {\n    name: \"hello\",\n    version: \"1.0.0\",\n    description: \"My Awesome CLI App\",\n  },\n  args: {\n    name: {\n      type: \"positional\",\n      description: \"Your name\",\n      required: true,\n    },\n    friendly: {\n      type: \"boolean\",\n      description: \"Use friendly greeting\",\n    },\n  },\n  setup({ args }) {\n    console.log(`now setup ${args.command}`);\n  },\n  cleanup({ args }) {\n    console.log(`now cleanup ${args.command}`);\n  },\n  run({ args }) {\n    console.log(`${args.friendly ? \"Hi\" : \"Greetings\"} ${args.name}!`);\n  },\n});\n\nrunMain(main);\n```\n\n```sh\nnode index.mjs john\n# Greetings john!\n```\n\n### Sub Commands\n\nSub commands can be nested recursively. Use lazy imports for large CLIs to avoid loading all commands at once.\n\n```js\nimport { defineCommand, runMain } from \"citty\";\n\nconst sub = defineCommand({\n  meta: { name: \"sub\", description: \"Sub command\" },\n  args: {\n    name: { type: \"positional\", description: \"Your name\", required: true },\n  },\n  run({ args }) {\n    console.log(`Hello ${args.name}!`);\n  },\n});\n\nconst main = defineCommand({\n  meta: { name: \"hello\", version: \"1.0.0\", description: \"My Awesome CLI App\" },\n  subCommands: { sub },\n});\n\nrunMain(main);\n```\n\nSubcommands support `meta.alias` (e.g., `[\"i\", \"add\"]`) and `meta.hidden: true` to hide from help output.\n\n### Lazy Commands\n\nFor large CLIs, lazy load sub commands so only the executed command is imported:\n\n```js\nconst main = defineCommand({\n  meta: { name: \"hello\", version: \"1.0.0\", description: \"My Awesome CLI App\" },\n  subCommands: {\n    sub: () => import(\"./sub.mjs\").then((m) => m.default),\n  },\n});\n```\n\n`meta`, `args`, and `subCommands` all accept `Resolvable<T>` values — a value, Promise, function, or async function — enabling lazy and dynamic resolution.\n\n### Hooks\n\nCommands support `setup` and `cleanup` functions called before and after `run()`. Only the executed command's hooks run. `cleanup` always runs, even if `run()` throws.\n\n```js\nconst main = defineCommand({\n  meta: { name: \"hello\", version: \"1.0.0\", description: \"My Awesome CLI App\" },\n  setup() {\n    console.log(\"Setting up...\");\n  },\n  cleanup() {\n    console.log(\"Cleaning up...\");\n  },\n  run() {\n    console.log(\"Hello World!\");\n  },\n});\n```\n\n### Plugins\n\nPlugins extend commands with reusable `setup` and `cleanup` hooks:\n\n```js\nimport { defineCommand, defineCittyPlugin, runMain } from \"citty\";\n\nconst logger = defineCittyPlugin({\n  name: \"logger\",\n  setup({ args }) {\n    console.log(\"Logger setup, args:\", args);\n  },\n  cleanup() {\n    console.log(\"Logger cleanup\");\n  },\n});\n\nconst main = defineCommand({\n  meta: { name: \"hello\", description: \"My CLI App\" },\n  plugins: [logger],\n  run() {\n    console.log(\"Hello!\");\n  },\n});\n\nrunMain(main);\n```\n\nPlugin `setup` hooks run before the command's `setup` (in order), `cleanup` hooks run after (in reverse). Plugins can be async or factory functions.\n\n## Arguments\n\n### Argument Types\n\n| Type         | Description                              | Example                     |\n| ------------ | ---------------------------------------- | --------------------------- |\n| `positional` | Unnamed positional args                  | `cli <name>`                |\n| `string`     | Named string options                     | `--name value`              |\n| `boolean`    | Boolean flags, supports `--no-` negation | `--verbose`                 |\n| `enum`       | Constrained to `options` array           | `--level=info\\|warn\\|error` |\n\n### Common Options\n\n| Option        | Description                                                   |\n| ------------- | ------------------------------------------------------------- |\n| `description` | Help text shown in usage output                               |\n| `required`    | Whether the argument is required                              |\n| `default`     | Default value when not provided                               |\n| `alias`       | Short aliases (e.g., `[\"f\"]`). Not for `positional`           |\n| `valueHint`   | Display hint in help (e.g., `\"host\"` renders `--name=<host>`) |\n\n### Example\n\n```js\nconst main = defineCommand({\n  args: {\n    name: { type: \"positional\", description: \"Your name\", required: true },\n    friendly: { type: \"boolean\", description: \"Use friendly greeting\", alias: [\"f\"] },\n    greeting: { type: \"string\", description: \"Custom greeting\", default: \"Hello\" },\n    level: {\n      type: \"enum\",\n      description: \"Log level\",\n      options: [\"debug\", \"info\", \"warn\", \"error\"],\n      default: \"info\",\n    },\n  },\n  run({ args }) {\n    console.log(`${args.greeting} ${args.name}! (level: ${args.level})`);\n  },\n});\n```\n\n### Boolean Negation\n\nBoolean args support `--no-` prefix. The negative variant appears in help when `default: true` or `negativeDescription` is set.\n\n### Case-Agnostic Access\n\nKebab-case args can be accessed as camelCase: `args[\"output-dir\"]` and `args.outputDir` both work.\n\n## Built-in Flags\n\n`--help` / `-h` and `--version` / `-v` are handled automatically. Disabled if your command defines args with the same names or aliases.\n\n## API\n\n| Function                      | Description                                                                |\n| ----------------------------- | -------------------------------------------------------------------------- |\n| `defineCommand(def)`          | Type helper for defining commands                                          |\n| `runMain(cmd, opts?)`         | Run a command with usage support and graceful error handling               |\n| `createMain(cmd)`             | Create a wrapper that calls `runMain` when invoked                         |\n| `runCommand(cmd, opts)`       | Parse args and run command/sub-commands; access `result` from return value |\n| `parseArgs(rawArgs, argsDef)` | Parse input arguments and apply defaults                                   |\n| `renderUsage(cmd, parent?)`   | Render command usage to a string                                           |\n| `showUsage(cmd, parent?)`     | Render usage and print to console                                          |\n| `defineCittyPlugin(def)`      | Type helper for defining plugins                                           |\n\n## Development\n\n- Clone this repository\n- Install latest LTS version of [Node.js](https://nodejs.org/en/)\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`\n- Install dependencies using `pnpm install`\n- Run interactive tests using `pnpm dev`\n\n## License\n\nMade with 💛 Published under [MIT License](./LICENSE).\n","publish_time":1768909783592,"_cnpm_publish_time":1768909783592,"dist-tags":{"latest":"0.2.2"}}