{"id":16721284,"url":"https://github.com/khalyomede/captain","last_synced_at":"2026-03-18T21:45:58.683Z","repository":{"id":52830765,"uuid":"358866382","full_name":"khalyomede/captain","owner":"khalyomede","description":"An opiniated command line parser that supports options and arguments.","archived":false,"fork":false,"pushed_at":"2021-04-17T12:48:19.000Z","size":13,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-30T19:47:24.800Z","etag":null,"topics":["arguments","arguments-parser","command","haxe","haxelib","options"],"latest_commit_sha":null,"homepage":"https://github.com/khalyomede/captain","language":"Haxe","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/khalyomede.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-17T11:55:00.000Z","updated_at":"2022-04-11T02:43:18.000Z","dependencies_parsed_at":"2022-08-23T08:20:20.111Z","dependency_job_id":null,"html_url":"https://github.com/khalyomede/captain","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/khalyomede/captain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fcaptain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fcaptain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fcaptain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fcaptain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khalyomede","download_url":"https://codeload.github.com/khalyomede/captain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fcaptain/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28956339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T18:30:42.805Z","status":"ssl_error","status_checked_at":"2026-01-31T18:30:19.593Z","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":["arguments","arguments-parser","command","haxe","haxelib","options"],"created_at":"2024-10-12T22:29:41.590Z","updated_at":"2026-01-31T21:38:48.177Z","avatar_url":"https://github.com/khalyomede.png","language":"Haxe","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Captain\r\n\r\nAn opiniated command line parser that supports options and arguments.\r\n\r\n## Summary\r\n\r\n- [About](#about)\r\n- [Features](#features)\r\n- [Installation](#installation)\r\n- [Examples](#examples)\r\n\r\n## About\r\n\r\nCaptain is a Haxe library to parse command line arguments.\r\n\r\n## Feature\r\n\r\n- Lets you define which arguments you expect using a class\r\n- Supports arguments and options with or without values\r\n- Can define if an option is required (only for the purpose of the help text documentation)\r\n- Generates the textual documentation based on your arguments and options definitions\r\n- Uses the Haxe [Option](Option) data structure to get options and arguments and check if they are provided\r\n\r\n## Installation\r\n\r\nIn your haxe project folder, run this command:\r\n\r\n```bash\r\nhaxelib install captain\r\n```\r\n\r\n## Examples\r\n\r\nAll these example assume you have the following folder structure:\r\n\r\n```txt\r\n.\r\n└── src/\r\n  └── Main.hx\r\n```\r\n\r\n- [1. Get an argument](#1-get-an-argument)\r\n- [2. Get an option](#2-get-an-option)\r\n- [3. Display instructions](#3-display-instructions)\r\n- [4. Define boolean options](#4-define-boolean-options)\r\n- [5. Define required options](#5-define-required-options)\r\n\r\n### 1. Get an argument\r\n\r\nIn this example, we will define and get an argument from the command line.\r\n\r\n```haxe\r\n// src/Main.hx\r\n\r\nimport captain.Command;\r\nimport haxe.ds.Option;\r\n\r\nfinal class Main {\r\n  public static function main() {\r\n  final command = new Command(Sys.args());\r\n\r\n  command.arguments = [\r\n    {\r\n      name: \"firstname\",\r\n      description: \"Your first name.\",\r\n    },\r\n  ];\r\n\r\n  final firstname = switch (command.getArgument(\"firstname\")) {\r\n    case Some(value): value;\r\n    case None: \"N/A\";\r\n  };\r\n\r\n  trace('Your first name is $firstname.');\r\n  }\r\n}\r\n```\r\n\r\nTo test it, run this command:\r\n\r\n```bash\r\n\u003e haxe --cwd src --library captain --run Main John\r\nYour first name is John.\r\n```\r\n\r\n### 2. Get an option\r\n\r\nIn this example, we will get an option from the command line.\r\n\r\n```haxe\r\n// src/Main.hx\r\n\r\nimport captain.Command;\r\nimport haxe.ds.Option;\r\n\r\nfinal class Main {\r\n  public static function main() {\r\n    final command = new Command();\r\n\r\n    command.options = [\r\n      {\r\n        name: \"date\",\r\n        shortName: \"d\",\r\n        description: \"The date to display.\",\r\n      }\r\n    ];\r\n\r\n    final date = switch (command.getOption(\"date\")) {\r\n      case Some(value): value;\r\n      case None: \"N/A\";\r\n    };\r\n\r\n    trace('The date is $date.');\r\n  }\r\n}\r\n```\r\n\r\nTo test it, run this command:\r\n\r\n```bash\r\n\u003e haxe --cwd src --library captain --run Main --date 2021-04-17\r\nThe date is 2021-04-17.\r\n```\r\n\r\n### 3. Display instructions\r\n\r\nIn this example, we will listen for the \"--help\" or \"-h\" option, and display the command instructions.\r\n\r\n```haxe\r\n// src/Main.hx\r\n\r\nimport captain.Command;\r\nimport haxe.ds.Option;\r\n\r\nfinal class Main {\r\n  public static function main() {\r\n    final command = new Command();\r\n\r\n    command.name = \"cmd\";\r\n    command.arguments = [\r\n      {\r\n        name: \"firstname\",\r\n        description: \"Your first name.\",\r\n      }\r\n    ];\r\n    command.options = [\r\n      {\r\n        name: \"help\",\r\n        shortName: \"h\",\r\n        boolean: true,\r\n        description: \"Display this help text.\",\r\n      },\r\n      {\r\n        name: \"date\",\r\n        shortName: \"d\",\r\n        description: \"The date to display.\",\r\n        required: true,\r\n      }\r\n    ];\r\n\r\n    final firstName = switch (command.getArgument(\"firstname\")) {\r\n      case Some(value): value;\r\n      case None: \"N/A\";\r\n    };\r\n\r\n    final date = switch (command.getOption(\"date\")) {\r\n      case Some(value): value;\r\n      case None: \"N/A\";\r\n    };\r\n\r\n    final displayHelp = switch (command.getOption(\"help\")) {\r\n      case Some(value): true;\r\n      case None: false;\r\n    };\r\n\r\n    if (displayHelp) {\r\n      trace(command.getInstructions());\r\n    } else {\r\n      trace('Your first name is $firstName and the date is $date.');\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nNow to test the help instructions, run this in your terminal:\r\n\r\n```bash\r\n\u003e haxe --cwd src --library captain --run Main --help\r\nUsage: cmd \u003cfirstname\u003e [options]\r\n\r\nArguments:\r\n  firstname   Your first name.\r\n\r\nOptions:\r\n  --date, -d  (required) The date to display.\r\n  --help, -h  (optional) Display this help text.\r\n```\r\n\r\n### 4. Define boolean options\r\n\r\nIn this example, we will define a boolean option (or often called \"flag\") and get its value from the command line arguments.\r\n\r\n```haxe\r\n// src/Main.hx\r\n\r\nimport captain.Command;\r\nimport haxe.ds.Option;\r\n\r\nfinal class Main {\r\n  public static function main() {\r\n    final command = new Command(Sys.args());\r\n\r\n    command.name = \"cmd\";\r\n    command.options = [\r\n      {\r\n        name: \"version\",\r\n        shortName: \"v\",\r\n        boolean: true,\r\n      },\r\n    ];\r\n\r\n    final displayVersion = switch (command.getOption(\"version\")) {\r\n      case Some(value): true;\r\n      case None: false;\r\n    };\r\n\r\n    if (displayVersion) {\r\n      trace('${command.name} version 0.1.0 (build 2021-04-17)');\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nTo test it, run this in your terminal:\r\n\r\n```haxe\r\n\u003e haxe --cwd src --library captain --run Main --version\r\ncmd version 0.1.0 (build 2021-04-17)\r\n```\r\n\r\nBoolean options do not take any values.\r\n\r\n### 5. Define required options\r\n\r\nIn this example, we will define a required option and get its value. Note that the required attribute is only used for displaying the option is required in the instructions (see example [3. Display instructions](#3-display-instructions)). This library does not perform command line argument validation.\r\n\r\n```haxe\r\n// src/Main.hx\r\n\r\nimport captain.Command;\r\nimport haxe.ds.Option;\r\n\r\nfinal class Main {\r\n  public static function main() {\r\n    final command = new Command();\r\n\r\n    command.optins = [\r\n      {\r\n        name: \"date\",\r\n        shortName: \"d\",\r\n        required: true,\r\n      },\r\n    ];\r\n\r\n    final date = switch (command.getOption(\"date\")) {\r\n      case Some(value): value;\r\n      case None: \"N/A\";\r\n    };\r\n\r\n    trace('The date is $date.');\r\n  }\r\n}\r\n```\r\n\r\nTo test it, run this command in your terminal:\r\n\r\n```bash\r\n\u003e haxe --cwd src --library captain --run Main --date 2021-04-17\r\nThe date is 2021-04-17.\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalyomede%2Fcaptain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhalyomede%2Fcaptain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalyomede%2Fcaptain/lists"}