{"id":21853521,"url":"https://github.com/abhi11210646/cli-flag-parser","last_synced_at":"2026-01-31T14:03:50.027Z","repository":{"id":254408318,"uuid":"846445490","full_name":"abhi11210646/cli-flag-parser","owner":"abhi11210646","description":"A simple and lightweight CLI flag parser for Node.js that allows you to easily define and parse command-line flags","archived":false,"fork":false,"pushed_at":"2024-09-27T17:39:51.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-24T21:59:43.642Z","etag":null,"topics":["cli","flag-parser","flags"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cli-flag-parser","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhi11210646.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-08-23T08:16:52.000Z","updated_at":"2024-09-27T17:39:55.000Z","dependencies_parsed_at":"2024-11-28T01:27:29.311Z","dependency_job_id":"79293bb0-53d2-4a93-9feb-03805d4cc6a2","html_url":"https://github.com/abhi11210646/cli-flag-parser","commit_stats":null,"previous_names":["abhi11210646/cli-flags","abhi11210646/cli-flag-parser"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/abhi11210646/cli-flag-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhi11210646%2Fcli-flag-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhi11210646%2Fcli-flag-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhi11210646%2Fcli-flag-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhi11210646%2Fcli-flag-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhi11210646","download_url":"https://codeload.github.com/abhi11210646/cli-flag-parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhi11210646%2Fcli-flag-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28944789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T13:02:32.153Z","status":"ssl_error","status_checked_at":"2026-01-31T13:00:07.528Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","flag-parser","flags"],"created_at":"2024-11-28T01:25:32.411Z","updated_at":"2026-01-31T14:03:50.012Z","avatar_url":"https://github.com/abhi11210646.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CLI Flag Parser\n\nThis is a simple and lightweight CLI flag parser for Node.js that allows you to easily define and parse command-line flags. \n\n## Features\n\n- **Register Flags**: Define flags with or without default values.\n- **Parse Arguments**: Automatically parse and retrieve the values of the flags passed via the command line.\n- **Boolean Flags**: Supports flags that can be toggled with a `--flag` syntax.\n\n## Installation\n\n```shell\nnpm install cli-flag-parser\n```\n\n## Usage\n\n### Registering Flags\n\nBefore parsing the arguments, you must register the flags that your application will accept. You can register a flag with or without a default value.\n\n```javascript\nconst flags = require(\"cli-flag-parser\");\n\n// Registering flags\nflags.registerFlag(\"name\", \"Name of the person\")\n     .registerFlag(\"age\", \"Age of the person\", \"21\");\n\n```\n### Parsing Arguments\nOnce the flags are registered, you can parse the command-line arguments using the parse() function.\n\n```javascript\nconst parsedFlags = flags.parse();\nconsole.log(parsedFlags);\n```\n\n## Example\nSuppose you run your script with the following command:\n\n```shell\nnode yourScript.js --name=John --age 30 --verbose -d --xyz=no\n```\nHere’s how you can use the parser to interpret the arguments:\n```javascript\nconst flags = require(\"cli-flag-parser\");\n\n// Registering flags\nflags.registerFlag(\"name\", \"name of person\")\n    .registerFlag(\"age\", \"age of person\")\n    .registerFlag(\"run\", \"run\", true)\n    .registerFlag(\"verbose\", \"verbose boolean flag\")\n    .registerFlag(\"d\", \"d boolean flag\");\n\n// Parsing the command-line arguments\nconst parsedFlags = flags.parse();\nconsole.log(parsedFlags);\n\nOutput:\n{\n    \"name\": \"John\",\n    \"age\": \"30\",\n    \"run\": true,  // defaultValue\n    \"verbose\": true,\n    \"d\": true\n}\n\nNote: 'xyz' is not present in the output because it was not registered.\n\n```\n## API Reference\n#### registerFlag(flag, description, defaultValue)\n- flag (string, required) - The name of the flag.\n- description (string, required)- A description of what the flag does\n- defaultValue (any, optional) - Default value of flag.\n#### parse()\n- Parses the command-line arguments and returns an object with the flag names as keys and their corresponding values.\n#### help()\n- Print the help text to the console.\n#### showHelp()\n- Print help text to the console and exit with error.\n#### unregisterFlags()\n- Unregister all the flags.\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhi11210646%2Fcli-flag-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhi11210646%2Fcli-flag-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhi11210646%2Fcli-flag-parser/lists"}