{"id":20645498,"url":"https://github.com/pedrohenriques/cli-inquirer","last_synced_at":"2026-04-23T10:32:21.424Z","repository":{"id":91937235,"uuid":"104358214","full_name":"PedroHenriques/cli-inquirer","owner":"PedroHenriques","description":"A NodeJS package for CLI parsing.","archived":false,"fork":false,"pushed_at":"2017-10-08T15:39:12.000Z","size":36,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T12:05:58.022Z","etag":null,"topics":["cli","cli-parser","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PedroHenriques.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-21T14:25:34.000Z","updated_at":"2023-02-13T22:51:23.000Z","dependencies_parsed_at":"2023-07-09T22:46:11.806Z","dependency_job_id":null,"html_url":"https://github.com/PedroHenriques/cli-inquirer","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"d2f8e57420083ca773f2c7c39ea815a3edcd3cbc"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroHenriques%2Fcli-inquirer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroHenriques%2Fcli-inquirer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroHenriques%2Fcli-inquirer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroHenriques%2Fcli-inquirer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PedroHenriques","download_url":"https://codeload.github.com/PedroHenriques/cli-inquirer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242714052,"owners_count":20173581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","cli-parser","nodejs"],"created_at":"2024-11-16T16:20:04.305Z","updated_at":"2026-04-23T10:32:21.396Z","avatar_url":"https://github.com/PedroHenriques.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/PedroHenriques/cli-inquirer.svg?branch=master)](https://travis-ci.org/PedroHenriques/cli-inquirer)\n\n# cli-inquirer\n\nA NodeJS package for CLI parsing.\nIt will ask the user for an instruction and then parse it into a command, options and flags.\n\n## Setup\n\nThe easiest way to start using this package is to install it using **npm**.\n\nIn you application run **`npm i cli-inquirer`** and then require it in your code with **`const { inquirer } = require('cli-inquirer');`**.\n\nThis package has typescript declaration files, so if you're writing typescript code you can use **`import { inquirer } from 'cli-inquirer';`**.\n\n## Summary of what this package does\n\nWhen the exported function is called, it will prompt the user (via the command line) for an instruction.\nOnce the user's input has been received it will be parsed and split into three components:\n\n- **Command:** the first \"word\" in the user's input.\n- **Options:** all \"words\" that are not the command or a flag.\n- **Flags:** all the \"words\" that start with a **-** or **--**, plus any associated arguments.\n\nA Promise is returned that will resolve with an Object (containg the 3 properties listed above) or rejects with an error message.\n\n**NOTE**: the options and flags can be provided by the user in any order.\n\n## Examples\n\nThe best way to check this package is to test it.\nCheck the folder `examples/` for example code.\n\n```\nnode examples/no-validation.js\nnode examples/with-validation.js\n```\n\n## Using this package\n\nThe package exposes one function named `inquirer` that receives 3 optional arguments:\n\n- **prompt:** The string that will be printed to the console when asking the user for an input. Defaults to `Please type a command? `.\n- **commandValidationData:** An object used to validate the command and the options. Defaults to `{}`.\n- **flagValidationData:** An object used to validate the flags. Defaults to `{}`.\n\nand returns a **promise** that resolves with an object with syntax\n\n```js\n{\n  command: string,\n  options: string[],\n  flags: string[][]\n}\n```\n\nor rejects with an error string.\n\n### commandValidationData\n\nIf an empty object is provided, no validation of the commands or options will be done.\n\nThe syntax for this object is\n\n```js\n{\n  [key: string]: (RegExp | null)[]\n}\n```\n\nwhere the **keys** are the valid commands and the **values** are arrays of regexp objects or null, defining the valid options for each command.\nThe order of the array will be the order the options are expected to be given.\nA `null` value defined that option as being non-required.\n\n### flagValidationData\n\nIf an empty object is provided, no validation of the flags will be done.\n\nThe syntax for this object is\n\n```js\n{\n  [key: string]: {\n    commands?: string[],\n    arg?: RegExp,\n    alias?: string\n  }\n}\n```\n\nwhere the **keys** are the valid flags and the **values** are objects defining each flag's valid data.\n\n- **commands:** Optional array of strings with the commands a flag is valid.\n- **arg:** Optional regexp object to match a flag's expected argument. It defines the flag as having an argument that must match the provided regexp.\nIf any argument is accepted, providing the regexp `/.+/` is enough.\nA flag's argument will be stored with the flag under the `flags` property of the returned object.\n- **alias:** Optional string with the name of the flag to copy the validation data from. Both flags will share the same validation data.\n\n## Example\n\nConsider the following code\n\n```js\n'use strict';\n\nconst { inquirer } = require(\"cli-inquirer\");\n\nconst commandData = {\n  'help': [/^files?$/i, /^\\w+$/i],\n  'create': [null],\n  'generate': []\n};\nconst flagData = {\n  '-f': {\n    commands: ['create', 'generate']\n  },\n  '--force': {\n    alias: '-f'\n  },\n  '-t': {\n    commands: ['help', 'create'],\n    arg: /^[^\\s]+$/i\n  },\n  '--target': {\n    alias: '-t'\n  }\n};\n\ninquirer('type an instruction: ', commandData, flagData).\nthen((instruction) =\u003e {\n  // continue your code\n}).\ncatch((reason) =\u003e {\n  // handle the error\n});\n```\n\nFor a user input of `create file -f --target ./src/newfile.js` the promise would resolve with\n```js\n{\n  command: \"create\",\n  options: [\"file\"],\n  flags: [[\"-f\"], [\"--target\", \"./src/newfile.js\"]]\n}\n```\n\n## Testing this package\n\n1. `cd` into the package directory\n2. run `npm install`\n3. run `npm run test -- ./test/**/*.test.js`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedrohenriques%2Fcli-inquirer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpedrohenriques%2Fcli-inquirer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedrohenriques%2Fcli-inquirer/lists"}