{"id":17030,"library":"make-cli","title":"make-cli: Declarative CLI Framework","description":"make-cli is a declarative framework for building command-line interfaces in Node.js, distinguished by its streamlined approach that centers around a single configuration object and a single function call. It aims to simplify CLI development by abstracting away much of the boilerplate often associated with argument parsing and command definition. The current stable version is 6.0.2, with major versions typically aligned with Node.js LTS releases (e.g., v5 required Node.js >= 20, v6 requires Node.js >= 22). Patch and minor releases occur regularly to address bugs and introduce minor enhancements. Built on top of Commander.js, make-cli leverages its robust parsing capabilities while offering a more functional and declarative API. This design makes it particularly appealing for developers who prefer a concise and config-driven style for their CLI tools, differentiating it from more imperative or class-based alternatives by providing a highly approachable entry point for creating complex command structures.","status":"active","version":"6.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/dword-design/make-cli","tags":["javascript","argument-parser","arguments","cli","command-line","command-line-interface","commander","commanderjs","declarative","typescript"],"install":[{"cmd":"npm install make-cli","lang":"bash","label":"npm"},{"cmd":"yarn add make-cli","lang":"bash","label":"yarn"},{"cmd":"pnpm add make-cli","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"make-cli is primarily an ESM-first package, especially from v5 onwards requiring recent Node.js versions. Direct CommonJS `require` might lead to errors.","wrong":"const makeCli = require('make-cli');","symbol":"makeCli","correct":"import makeCli from 'make-cli';"},{"note":"For TypeScript users, import types separately for configuration options.","symbol":"MakeCliOptions","correct":"import type { MakeCliOptions } from 'make-cli';"},{"note":"The primary export is a default export, not a named export.","wrong":"import { makeCli } from 'make-cli';","symbol":"makeCli (named import)","correct":"import makeCli from 'make-cli';"}],"quickstart":{"code":"#!/usr/bin/env node\n\nimport makeCli from 'make-cli';\nimport { resolve } from 'path';\n\ninterface MyCliOptions {\n  yes?: boolean;\n  value: string;\n  force?: boolean;\n}\n\nmakeCli<MyCliOptions>({\n  version: '0.1.0',\n  name: 'my-cli',\n  usage: 'A simple demonstration CLI for make-cli',\n  arguments: '<remote> [extra]',\n  options: [\n    {\n      name: '-y, --yes',\n      description: 'Skip interactive prompts and confirm actions',\n      default: false\n    },\n    {\n      name: '--value <value>',\n      description: 'Specifies an important configuration value',\n      defaultValue: 'default_foo',\n      choices: ['default_foo', 'bar', 'baz']\n    }\n  ],\n  action: async (remote: string, extra: string | undefined, options: MyCliOptions) => {\n    console.log(`Executing action for remote: ${remote || '[no remote]'}`);\n    console.log(`Extra argument: ${extra || '[no extra]'}`);\n    console.log(`Options: Yes=${options.yes}, Value=${options.value}`);\n    \n    if (options.yes) {\n      console.log('Skipping interactive confirmation due to --yes flag.');\n    } else {\n      console.log('Performing interactive confirmation...');\n    }\n    console.log(`Resolved path example: ${resolve('.')}`);\n    await new Promise(resolve => setTimeout(resolve, 100)); // Simulate async work\n    console.log('Main action completed.');\n  },\n  commands: [\n    {\n      name: 'push',\n      description: 'Pushes changes to the remote repository',\n      arguments: '<remote>',\n      options: [\n        {\n          name: '-f, --force',\n          description: 'Force push',\n          default: false\n        }\n      ],\n      handler: async (remote: string, { force }: { force: boolean }) => {\n        console.log(`Executing 'push' command to ${remote} with force=${force}`);\n        await new Promise(resolve => setTimeout(resolve, 50));\n        console.log('Push command executed.');\n      }\n    }\n  ]\n});","lang":"typescript","description":"This example demonstrates defining a CLI with global arguments and options, an main action handler, and a subcommand. It includes TypeScript types, async operations, and option validation with 'choices'."},"warnings":[{"fix":"Upgrade your Node.js environment to version 22 or newer, or downgrade make-cli to a compatible major version (e.g., v5 for Node.js >= 20).","message":"Version 6.0.0 and above of make-cli requires Node.js version 22 or higher. Older Node.js versions will result in compatibility issues.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Upgrade your Node.js environment to version 20 or newer, or stick to make-cli v4.x.","message":"Version 5.0.0 of make-cli introduced a minimum requirement of Node.js version 20. Users on older Node.js versions will encounter errors.","severity":"breaking","affected_versions":">=5.0.0 <6.0.0"},{"fix":"Update to make-cli version 6.0.2 or newer to ensure CLI actions correctly wait for all promises to resolve before the process exits. Ensure your action/handler functions are `async` and `await` all relevant promises.","message":"In `make-cli` versions prior to 6.0.2, CLI actions or handlers might not always wait for asynchronous operations to complete before exiting, leading to premature process termination.","severity":"gotcha","affected_versions":">=6.0.0 <6.0.2"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure your project's `package.json` includes `\"type\": \"module\"`, or rename your file to `.mjs`. Alternatively, ensure your Node.js version meets the minimum requirement for `make-cli` (v6 requires Node.js >= 22).","cause":"Attempting to use ES module `import` syntax in a CommonJS context (e.g., a `.js` file without `\"type\": \"module\"` in `package.json`, or an older Node.js version).","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"If publishing, add `\"bin\": \"./cli.js\"` (or your script path) to `package.json`. Locally, run `npm link` in your project directory for development, or ensure your script has execution rights with `chmod +x ./cli.js`.","cause":"The CLI executable is not correctly configured in your `package.json`'s `bin` field, not installed globally, or the script lacks execution permissions.","error":"make-cli: command not found"},{"fix":"Ensure the argument passed for the option (`--value` in this example) is one of the predefined `choices`. For example, use `--value bar` instead of `--value invalid`.","cause":"The value provided for an option with `choices` specified in the configuration does not match any of the allowed choices.","error":"Error [commander.invalidArgument]: argument 'value' is invalid, choices are 'foo', 'bar', 'baz'"}],"ecosystem":"npm","meta_description":null}