{"id":17994902,"url":"https://github.com/TheManticoreProject/goopts","last_synced_at":"2025-09-03T17:32:38.120Z","repository":{"id":259177789,"uuid":"876664265","full_name":"p0dalirius/goopts","owner":"p0dalirius","description":"goopts, a Go library to parse arguments given in command line to a program. ","archived":false,"fork":false,"pushed_at":"2024-11-14T16:14:05.000Z","size":384,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-24T18:44:30.511Z","etag":null,"topics":["arguments","cli","command","golang-library","line","parsing"],"latest_commit_sha":null,"homepage":"https://podalirius.net/","language":"Go","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/p0dalirius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"p0dalirius","patreon":"Podalirius"}},"created_at":"2024-10-22T11:01:09.000Z","updated_at":"2024-11-14T16:14:10.000Z","dependencies_parsed_at":"2024-10-23T09:04:21.786Z","dependency_job_id":"080a7872-c3f9-407e-a5a9-a6d7dee0216c","html_url":"https://github.com/p0dalirius/goopts","commit_stats":null,"previous_names":["p0dalirius/goopts"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p0dalirius%2Fgoopts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p0dalirius%2Fgoopts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p0dalirius%2Fgoopts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p0dalirius%2Fgoopts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/p0dalirius","download_url":"https://codeload.github.com/p0dalirius/goopts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231906361,"owners_count":18443975,"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":["arguments","cli","command","golang-library","line","parsing"],"created_at":"2024-10-29T20:17:08.159Z","updated_at":"2025-09-03T17:32:38.095Z","avatar_url":"https://github.com/p0dalirius.png","language":"Go","funding_links":["https://github.com/sponsors/p0dalirius","https://patreon.com/Podalirius"],"categories":[],"sub_categories":[],"readme":"![](./.github/banner.png)\n\n\u003cp align=\"center\"\u003e\n    goopts, a Go library to parse arguments given in command line to a program.\n    \u003cbr\u003e\n    \u003ca href=\"https://github.com/p0dalirius/goopts/actions/workflows/unit_tests.yaml\" title=\"Build\"\u003e\u003cimg alt=\"Build and Release\" src=\"https://github.com/p0dalirius/goopts/actions/workflows/unit_tests.yaml/badge.svg\"\u003e\u003c/a\u003e\n    \u003cimg alt=\"GitHub release (latest by date)\" src=\"https://img.shields.io/github/v/release/p0dalirius/goopts\"\u003e\n    \u003ca href=\"https://twitter.com/intent/follow?screen_name=podalirius_\" title=\"Follow\"\u003e\u003cimg src=\"https://img.shields.io/twitter/follow/podalirius_?label=Podalirius\u0026style=social\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.youtube.com/c/Podalirius_?sub_confirmation=1\" title=\"Subscribe\"\u003e\u003cimg alt=\"YouTube Channel Subscribers\" src=\"https://img.shields.io/youtube/channel/subscribers/UCF_x5O7CSfr82AfNVTKOv_A?style=social\"\u003e\u003c/a\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\ngoopts is a powerful and flexible library designed to simplify the parsing of command-line arguments in Go applications. Inspired by popular argument parsing libraries from other languages, goopts aims to provide developers with a robust, easy-to-use interface for handling various argument types, including positional arguments, named options, flags, and more. The library also supports advanced features like argument groups, mutually exclusive options, and dependency handling, making it an excellent choice for building feature-rich CLI tools.\n\nWhether you are developing a simple utility or a complex command-line application, goopts offers the tools you need to parse and manage user input efficiently and effectively.\n\n## Purpose\n\nThe purpose of goopts is to:\n\n- Provide a straightforward and intuitive way to define and parse command-line arguments.\n- Support multiple types of arguments including strings, integers, booleans, lists, and maps.\n- Enable the grouping of arguments, including mutually exclusive groups and dependent arguments.\n- Offer clear, customizable help messages for your command-line tools.\n- Allow for flexible configuration and easy integration into existing Go projects.\n\n## Documentation\n\n- [1. Getting Started](./vendor/docs/1.%20Getting%20Started/README.md)\n    - [1.1 Installation Instructions](./vendor/docs/1.%20Getting%20Started/1.%20Installation%20Instructions/README.md)\n    - [1.2 Basic Example of Setting Up goopts](./vendor/docs/1.%20Getting%20Started/2.%20Basic%20Example%20of%20Setting%20Up%20goopts/README.md)\n    - [1.3 Positional vs. Named Arguments](./vendor/docs/1.%20Getting%20Started/3.%20Positional%20vs.%20Named%20Arguments/README.md)\n- [2. Examples](./vendor/docs/2.%20Examples/README.md)\n    - [2.1. Basic Example](./vendor/docs/2.%20Examples/1.%20Basic%20Example/README.md)\n    - [2.2. Parsing HTTP Headers and Other Advanced Use Cases](./vendor/docs/2.%20Examples/2.%20Parsing%20HTTP%20Headers%20and%20Other%20Advanced%20Use%20Cases/README.md)\n    - [2.3. Complex CLI Tool with Multiple Groups](./vendor/docs/2.%20Examples/3.%20Complex%20CLI%20Tool%20with%20Multiple%20Groups/README.md)\n- [3. Positionals](./vendor/docs/3.%20Positionals/README.md)\n    - [3.1. Integer Argument](./vendor/docs/3.%20Positionals/1.%20Integer%20Positional%20Argument/README.md)\n    - [3.2. String Argument](./vendor/docs/3.%20Positionals/2.%20String%20Positional%20Argument/README.md)\n- [4. Arguments](./vendor/docs/4.%20Arguments/README.md)\n    - [3. Simple Argument Types](./vendor/docs/4.%20Arguments/3.%20Simple%20Argument%20Types/README.md)\n        - [4.3.1. Boolean Argument](./vendor/docs/4.%20Arguments/3.%20Simple%20Argument%20Types/1.%20Boolean%20Argument/README.md)\n        - [4.3.2. Integer Argument](./vendor/docs/4.%20Arguments/3.%20Simple%20Argument%20Types/2.%20Integer%20Argument/README.md)\n        - [4.3.3. String Argument](./vendor/docs/4.%20Arguments/3.%20Simple%20Argument%20Types/3.%20String%20Argument/README.md)\n    - [4. Complex Argument Types](./vendor/docs/4.%20Arguments/4.%20Complex%20Argument%20Types/README.md)\n        - [4.4.1. TCP Port](./vendor/docs/4.%20Arguments/4.%20Complex%20Argument%20Types/1.%20TCP%20Port/README.md)\n        - [4.4.2. List of Strings](./vendor/docs/4.%20Arguments/4.%20Complex%20Argument%20Types/2.%20List%20of%20Strings/README.md)\n        - [4.4.3. Map of HTTP Headers](./vendor/docs/4.%20Arguments/4.%20Complex%20Argument%20Types/3.%20Map%20of%20HTTP%20Headers/README.md)\n- [5. Argument Groups](./vendor/docs/5.%20Argument%20Groups/README.md)\n    - [1. Mutually Exclusive Argument Groups](./vendor/docs/5.%20Argument%20Groups/1.%20Mutually%20Exclusive%20Argument%20Groups/README.md)\n    - [2. Dependent Argument Groups](./vendor/docs/5.%20Argument%20Groups/2.%20Dependent%20Argument%20Groups/README.md)\n- [6. Best Practices](./vendor/docs/6.%20Best%20Practices/README.md)\n    - [1. Organizing Your Code with goopts](./vendor/docs/6.%20Best%20Practices/1.%20Organizing%20Your%20Code%20with%20goopts/README.md)\n    - [2. Common Pitfalls and How to Avoid Them](./vendor/docs/6.%20Best%20Practices/2.%20Common%20Pitfalls%20and%20How%20to%20Avoid%20Them/README.md)\n\n## Example code\n\nHere is an example code to illustrate a few of the features of [goopts](https://github.com/p0dalirius/goopts):\n\n```go\nimport (\n\t\"fmt\"\n\n\t\"github.com/p0dalirius/goopts/parser\"\n)\n\nvar (\n\t// Positional arguments\n\tfilePath     string\n\toutputFolder string\n\n\t// Authentication flags\n\tdbHost     string\n\tdbUsername string\n\tdbPassword string\n\tdbPort     int\n\n\t// Server settings flags\n\tserverIP   string\n\tserverPort int\n\n\t// Feature flags\n\tenableLogging     bool\n\tdisableEncryption bool\n)\n\nfunc parseArgs() {\n\t// Create a new arguments parser with a custom banner\n\tap := parser.ArgumentsParser{Banner: \"PoC of goopts parsing v.1.1 - by Remi GASCOU (Podalirius)\"}\n\n\t// Define positional arguments\n\tap.NewStringPositionalArgument(\u0026filePath, \"filepath\", \"Path to the input file.\")\n\tap.NewStringPositionalArgument(\u0026outputFolder, \"outputfolder\", \"Destination folder for output.\")\n\n\t// Define global flags\n\tap.NewBoolArgument(\u0026enableLogging, \"-l\", \"--enable-logging\", true, \"Enable logging during execution.\")\n\tap.NewBoolArgument(\u0026disableEncryption, \"-e\", \"--disable-encryption\", false, \"Disable encryption for data transfer.\")\n\n\t// Define an argument group for database authentication\n\tgroup_dbAuth, err := ap.NewArgumentGroup(\"Database Authentication\")\n\tif err != nil {\n\t\tfmt.Printf(\"[error] Error creating ArgumentGroup: %s\\n\", err)\n\t} else {\n\t\tgroup_dbAuth.NewStringArgument(\u0026dbHost, \"-H\", \"--db-host\", \"\", true, \"Hostname or IP of the database server.\")\n\t\tgroup_dbAuth.NewStringArgument(\u0026dbUsername, \"-U\", \"--db-username\", \"\", true, \"Username for database authentication.\")\n\t\tgroup_dbAuth.NewStringArgument(\u0026dbPassword, \"-P\", \"--db-password\", \"\", true, \"Password for database authentication.\")\n\t\tgroup_dbAuth.NewIntArgument(\u0026dbPort, \"-p\", \"--db-port\", 3306, false, \"Port number of the database server.\")\n\t}\n\n\t// Define an argument group for server settings\n\tgroup_serverSettings, err := ap.NewArgumentGroup(\"Server Settings\")\n\tif err != nil {\n\t\tfmt.Printf(\"[error] Error creating ArgumentGroup: %s\\n\", err)\n\t} else {\n\t\tgroup_serverSettings.NewStringArgument(\u0026serverIP, \"-i\", \"--server-ip\", \"\", true, \"IP address of the server to connect.\")\n\t\tgroup_serverSettings.NewTcpPortArgument(\u0026serverPort, \"-s\", \"--server-port\", 8080, false, \"Port on which the server listens.\")\n\t}\n\n\t// Parse the flags\n\tap.Parse()\n}\n```\n\nThis results in the following arguments and usage printing:\n\n![](./.github/example.png)\n\n## Contributing\n\nPull requests are welcome. Feel free to open an issue if you want to add other features.\n\n## Credits\n  - [@p0dalirius](https://github.com/p0dalirius) for the creation of the [goopts](https://github.com/p0dalirius/goopts) library before transferring it to TheManticoreProject.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTheManticoreProject%2Fgoopts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTheManticoreProject%2Fgoopts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTheManticoreProject%2Fgoopts/lists"}