{"id":36740544,"url":"https://github.com/nktknshn/yargs-command-wrapper","last_synced_at":"2026-01-12T12:28:25.781Z","repository":{"id":168193072,"uuid":"643221820","full_name":"nktknshn/yargs-command-wrapper","owner":"nktknshn","description":"wraps yargs command to make it more typesafe","archived":false,"fork":false,"pushed_at":"2024-09-29T15:50:26.000Z","size":865,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-02T04:22:44.943Z","etag":null,"topics":["args-parser","typescript","yargs"],"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/nktknshn.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":"2023-05-20T13:32:21.000Z","updated_at":"2024-09-29T15:50:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"49a50062-a40c-453a-81fd-4ab2ac31b64e","html_url":"https://github.com/nktknshn/yargs-command-wrapper","commit_stats":{"total_commits":113,"total_committers":2,"mean_commits":56.5,"dds":"0.026548672566371723","last_synced_commit":"443786b59126c15d700bc03769e6d857640e81a8"},"previous_names":["nktknshn/yargs-command-wrapper"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nktknshn/yargs-command-wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nktknshn%2Fyargs-command-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nktknshn%2Fyargs-command-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nktknshn%2Fyargs-command-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nktknshn%2Fyargs-command-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nktknshn","download_url":"https://codeload.github.com/nktknshn/yargs-command-wrapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nktknshn%2Fyargs-command-wrapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28338976,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"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":["args-parser","typescript","yargs"],"created_at":"2026-01-12T12:28:25.719Z","updated_at":"2026-01-12T12:28:25.769Z","avatar_url":"https://github.com/nktknshn.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\n\u003cp\u003e\n  \u003ca href=\"https://github.com/nktknshn/yargs-command-wrapper/actions\"\u003e\n    \u003cimg src=\"https://github.com/nktknshn/yargs-command-wrapper/actions/workflows/node.js.yml/badge.svg?branch=master\" alt=\"build status\" height=\"20\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/yargs-command-wrapper\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/yargs-command-wrapper.svg\" alt=\"npm link\" height=\"20\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nThis wrapper enables the parsing of commands and subcommands into a unified set\nof types that can be handled independently. Additionally, it simplifies the process\nof creating a handler for these commands\n\nThe inferred union type of the parsed arguments is as follows:\n\n\u003c!-- dprint-ignore --\u003e\n```typescript\ntype ParsedArgs = \n| { command: \"server\"; subcommand: \"start\"; argv: { port: number; } }\n| { command: \"client\"; subcommand: \"connect\"; argv: { host: string; port: number; } }\n| { command: \"client\"; subcommand: \"config\"; subsubcommand: \"get\"; argv: { key?: string; file: string; } }\n| { command: \"client\"; subcommand: \"config\"; subsubcommand: \"set\"; argv: { key: string; value: string; file: string; } }\n```\n\n# Installation\n\n```bash\nnpm install --save yargs-command-wrapper\n```\n\n# Examples\n\n**API might change in the future.**\n\n[https://github.com/nktknshn/yargs-command-wrapper/tree/master/examples](https://github.com/nktknshn/yargs-command-wrapper/tree/master/examples)\n\n[https://github.com/nktknshn/idrive-cli](https://github.com/nktknshn/idrive-cli/blob/ff36093d6a874d7da2605d19cb0a686a845d39ba/src/cli/drive/handler.ts#L12)\n\n```typescript\nimport {\n  buildAndParse,\n  command,\n  composeCommands,\n  createHandlerFor,\n  Either,\n  failClient,\n  subcommands,\n} from \"yargs-command-wrapper\";\n\nconst config = composeCommands(\n  _ =\u003e\n    _.options({\n      file: { alias: \"f\", type: \"string\", default: \"config.json\" },\n    }),\n  command(\n    [\"get [key]\", \"g\"],\n    \"get config value\",\n    _ =\u003e _.positional(\"key\", { type: \"string\" }),\n  ),\n  command(\n    [\"set \u003ckey\u003e \u003cvalue\u003e\", \"s\"],\n    \"set config key\",\n    _ =\u003e\n      _\n        .positional(\"value\", { type: \"string\", demandOption: true })\n        .positional(\"key\", { type: \"string\", demandOption: true }),\n  ),\n);\n\nconst serverStart = command(\n  [\"start\", \"sta\"],\n  \"start server\",\n  _ =\u003e _.option(\"port\", { type: \"number\", default: 8080 }),\n);\n\nconst serverStop = command(\n  [\"stop\", \"sto\"],\n  \"stop server\",\n  _ =\u003e _.option(\"force\", { type: \"boolean\", default: false }),\n);\n\nconst cmd = composeCommands(\n  _ =\u003e _.option(\"debug\", { alias: \"d\", type: \"boolean\", default: false }),\n  serverStart,\n  serverStop,\n  subcommands([\"config\", \"c\"], \"config management\", config),\n  // allow command without a subcommand\n).selfHandle(true);\n\nconst { result, yargs } = buildAndParse(cmd, process.argv.slice(2));\n\nif (Either.isLeft(result)) {\n  failClient(yargs, result);\n}\n\nif (result.right.argv.debug) {\n  console.log(\"debug mode enabled\");\n}\n\nif (result.right.command === undefined) {\n  console.log(`cli was called without any commands`);\n  yargs.showHelp();\n}\nelse if (result.right.command === \"start\") {\n  console.log(`starting server on port ${result.right.argv.port}`);\n}\nelse if (result.right.command === \"stop\") {\n  console.log(`stopping server ${result.right.argv.force ? \"forcefully\" : \"\"}`);\n}\nelse if (result.right.command === \"config\") {\n  if (result.right.subcommand === \"get\") {\n    console.log(`getting config key ${result.right.argv.key ?? \"all\"}`);\n  }\n  else {\n    console.log(\n      `setting config key ${result.right.argv.key} to ${result.right.argv.value}`,\n    );\n  }\n}\n\n// or by using createHandlerFor:\nconst handler = createHandlerFor(cmd, {\n  \"$self\": ({ debug }) =\u003e {\n    console.log(\n      `cli was called without any commands. debug: ${debug ? \"yes\" : \"no\"}`,\n    );\n    yargs.showHelp();\n  },\n  config: {\n    get: ({ key, file, debug }) =\u003e {\n      console.log(`getting config ${file} key ${key ?? \"all\"}`);\n    },\n    set: ({ key, value, file, debug }) =\u003e {\n      console.log(`setting config ${file} key ${key} to ${value}`);\n    },\n  },\n  start: ({ port, debug }) =\u003e {\n    console.log(`starting server on port ${port}`);\n  },\n  stop: ({ force, debug }) =\u003e {\n    console.log(`stopping server ${force ? \"forcefully\" : \"\"}`);\n  },\n});\n\nhandler.handle(result.right);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnktknshn%2Fyargs-command-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnktknshn%2Fyargs-command-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnktknshn%2Fyargs-command-wrapper/lists"}