{"id":21244431,"url":"https://github.com/unyt-org/command-line-args","last_synced_at":"2026-04-24T20:31:27.256Z","repository":{"id":189148283,"uuid":"680137109","full_name":"unyt-org/command-line-args","owner":"unyt-org","description":"Declare and parse command line options in deno, with automatic help generation","archived":false,"fork":false,"pushed_at":"2023-10-16T20:43:27.000Z","size":122,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-15T21:38:29.733Z","etag":null,"topics":["args-parser","command-line","deno","unyt"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/unyt-org.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,"zenodo":null},"funding":{"github":["unyt-org"],"patreon":"unyt","custom":["https://unyt.org/donate","https://shop.unyt.org"]}},"created_at":"2023-08-18T12:35:02.000Z","updated_at":"2023-10-17T12:59:08.000Z","dependencies_parsed_at":"2025-06-28T09:36:16.731Z","dependency_job_id":"b8960d4b-afe7-40de-98f9-f9a2ca9cadf0","html_url":"https://github.com/unyt-org/command-line-args","commit_stats":null,"previous_names":["unyt-org/command-line-args"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/unyt-org/command-line-args","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unyt-org%2Fcommand-line-args","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unyt-org%2Fcommand-line-args/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unyt-org%2Fcommand-line-args/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unyt-org%2Fcommand-line-args/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unyt-org","download_url":"https://codeload.github.com/unyt-org/command-line-args/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unyt-org%2Fcommand-line-args/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32239472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: 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":["args-parser","command-line","deno","unyt"],"created_at":"2024-11-21T01:25:26.453Z","updated_at":"2026-04-24T20:31:27.231Z","avatar_url":"https://github.com/unyt-org.png","language":"TypeScript","funding_links":["https://github.com/sponsors/unyt-org","https://patreon.com/unyt","https://unyt.org/donate","https://shop.unyt.org"],"categories":[],"sub_categories":[],"readme":"# Command Line Argument Manager\n\nThis library provides a straightforward way to declare and parse command line\noptions and sub-commands for a deno program.\n\nIt comes with the following features:\n\n- Input validation\n- Type-safe definitions\n- Default arguments\n- Resolution of relative paths arguments\n- Automatic help page display in CLI (`--help`)\n- Automatic help file generation (`--generate-help`)\n\nWith this library, it is possible for multiple modules in a program to declare\nand access their own command line arguments at the same time.\n\nThis libary is based on \u003chttps://deno.land/std/flags/mod.ts\u003e.\n\n## Defining Command Line Options\n\n```typescript\n// Example: time-machine.ts\n\n// create a CommandLineOptions instance\nconst options = new CommandLineOptions(\n  \"Time Machine 1.0\",\n  \"Command-line time travel at your fingertips\",\n);\n\n// declare options and get their values at runtime\nconst location = options.option(\"location\", {\n  type: \"string\",\n  default: \"52° 12’ 21” N, 0° 7’ 4.7” E\",\n  description: \"Travel destination\",\n});\n\nconst time = options.option(\"time\", {\n  type: \"string\",\n  required: true,\n  description: \"The time at your destination\",\n});\n\nconst travelers = options.option(\"traveler\", {\n  type: \"string\",\n  required: true,\n  multiple: true,\n  description: \"The names of all participating time travelers\",\n});\n\n// capture options (optional, but--help)\nawait CommandLineOptions.capture();\n\n// log the provided options\nconsole.log({\n  time,\n  travelers,\n  location,\n});\n```\n\n\u003e [!NOTE] \n\u003e The command line options should always be defined at the top-level\n\u003e scope of a module before any other program logic is done.\n\u003e\n\u003e It is recommended to use `CommandLineOptions.capture()` at the end of the\n\u003e options declaration to prevent unexpected behaviour when running the program\n\u003e with `--help`. The program is guaranteed to stop running beyond this point\n\u003e when starting it with `--help`.\n\nNow you can run the program and pass arguments, e.g.:\n\n```bash\ndeno run -A ./time-machine.ts --time \"June 28, 2009\" --traveler \"Stephen Hawking\" --traveler \"Albert Einstein\"\n```\n\nThe options are printed out:\n\n```js\n{\n  time: \"June 28, 2009\",\n  travelers: [ \"Stephen Hawking\", \"Albert Einstein\" ],\n  location: \"52° 12’ 21” N, 0° 7’ 4.7” E\"\n}\n```\n\nThe help page can also be display by starting the program with the `--help`\noption (Other options are ignored in this case):\n\n```bash\ndeno run -A ./time-machine.ts --help\n```\n\n![Help Page 1](./res/help-1.png)\n\n## Defining Custom Sub-Commands with Options\n\n```typescript\n// Example: time-machine-2.ts\n\n// create a CommandLineOptions instance\nconst options = new CommandLineOptions(\n  \"Time Machine 1.0\",\n  \"Command-line time travel at your fingertips\",\n);\n\n// declare commands with options and get their values at runtime\nconst advancedTravelOptions = options.command(\"advanced\", {\n  \"pardox-prevention\": {\n    type: \"boolean\",\n    aliases: [\"p\"],\n    description: \"Enable paradox prevention measures (recommended)\",\n  },\n\n  \"speed\": {\n    type: \"number\",\n    default: 100,\n    aliases: [\"s\"],\n    description: \"Time travel speed in years/second\",\n  },\n\n  \"backup-location\": {\n    type: \"URL\",\n    default: \"/tmp/time-travel-backup\",\n    description: \"Memory backup directory\",\n  },\n});\n\n// capture options\nawait CommandLineOptions.capture();\n\n// log the provided options\nconsole.log(advancedTravelOptions);\n```\n\n\u003e [!NOTE]\n\u003e You can also define more than one sub-command with multiple\n\u003e `option.command()` declarations.\n\nThe program can now be started with the `advanced` subcommand and the declared\noptions:\n\n```shell\n$ deno run -A ./time-machine-2.ts advanced --speed 4000 --backup-location ../backups/\n```\n\nThis produces the following output:\n\n```js\n{\n  \"pardox-prevention\": false,\n  \"speed\": 1000,\n  \"backup-location\": URL {\"/home/marty/backups/\"}\n}\n```\n\nIf the program is called with a different or no command, `advancedTravelOptions`\nis `null`.\n\nThe help page for this option declaration looks like this:\n![Help Page 2](./res/help-2.png)\n\n## Generating the static help page file\n\nThe builtin `--help` command can always be used to print the help page. It\nregisters all provided sub-commands and options at runtime and exits the program\nas soon as possible.\n\nThis works fine in most cases, but it has two disadvantages:\n\n- Every time the help page is displayed, the program has to run until the point\n  where all top-level command line options are defined\n- Any command line options that are not defined at the top-level (e.g. loaded\n  asynchronously or conditionally) will not be captured and displayed\n\nThis can be prevented by generating a static help file that can be used as a\ncache when running `--help`. This file also serves a human-readable help\ndocument.\n\nIn this scenario, custom command line options that are not immediately\ninitialized at the top level scope might not yet be loaded and not shown on the\nhelp page.\n\nFor this reason, this tool allows you to generate a static help page, `RUN.md`\nwhich also serves as a human readable help document.\n\nTo generate or update this file, run your program with the `--generate-help`\noption. The file is named `RUN.md` and will be generated in the current working\ndirectory.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funyt-org%2Fcommand-line-args","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funyt-org%2Fcommand-line-args","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funyt-org%2Fcommand-line-args/lists"}