{"id":24961872,"url":"https://github.com/sg3des/argum","last_synced_at":"2025-04-10T21:40:33.840Z","repository":{"id":80546639,"uuid":"84719416","full_name":"sg3des/argum","owner":"sg3des","description":"Parse incoming arguments in to structure","archived":false,"fork":false,"pushed_at":"2025-04-09T07:36:32.000Z","size":62,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T08:35:17.484Z","etag":null,"topics":["arguments","flags","go","golang","struct"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sg3des.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2017-03-12T11:10:56.000Z","updated_at":"2025-04-09T07:36:16.000Z","dependencies_parsed_at":"2023-10-16T07:06:05.871Z","dependency_job_id":null,"html_url":"https://github.com/sg3des/argum","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sg3des%2Fargum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sg3des%2Fargum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sg3des%2Fargum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sg3des%2Fargum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sg3des","download_url":"https://codeload.github.com/sg3des/argum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248305782,"owners_count":21081561,"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","flags","go","golang","struct"],"created_at":"2025-02-03T08:58:06.304Z","updated_at":"2025-04-10T21:40:33.811Z","avatar_url":"https://github.com/sg3des.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/sg3des/argum.svg?branch=master)](https://travis-ci.org/sg3des/argum)\n\n# Argum\n\nArgum is package for parse arguments into struct, inspired by [alexflint/go-arg](https://github.com/alexflint/go-arg).\n\nWARNING! work in progress, backward compatible is not guaranteed!\n\n```shell\ngo get github.com/sg3des/argum\n```\n\n# Description\n\nSetting up available arguments using tags:\n\n * `argum:\"-s\"` - set short signature\n * `argum:\"--str\"` - set long signature\n * `argum:\"-s,--str\"` - set short and long signature\n * `argum:\"req\"` or `argum:\"required\"`  - required argument\n * `argum:\"pos\"` or `argum:\"positional\"` - positional argument\n * `argum:\"oneof\"` - this keyword work only on internal struct, user can select only one of nested fields, itself structure ignored from command line\n * `argum:\"emb\"` or `argum:\"embedded\"` - its keyword work only on for internal struct, and indicates that the struct name should be ignored\n * `help:\"some help\"` - help description for this option\n * `default:\"value\"` - default value\n * if struct field not have tag *argum*, then parse it automate\n\nArgum, use 3 key tags for parse structure - *argum*, *help*, *default* - it's more convenient.\n\n# Usage\n\n```go\nvar args struct {\n\tA string                      //parsed to -a\n\tArg string                    //parsed to --arg\n\tSomeArg string `argum:\"-s\"`   //only -s\n\tOneMoreArg string `argum:\"-o,--onemore\"`  //both keys: -o, --onemore\n}\nargum.MustParse(\u0026args)\n```\n\n### Set software version\n\n```go\nargum.Version = \"some version\"\nargum.MustParse(\u0026args)\n```\n\n### Default values\n\n```go\nvar args struct {\n\tString string    `default:\"some string\"`\n\tSlice  []string  `default:\"one,two,three\"`\n\tIntSlice []int `argum:\"--int\" default:\"0,2,3\"`\n}\n```\n\nDefault value for slice automatic split by comma character\n\n### Joined boolean arguments\n\n```go\nvar args struct {\n\tA bool\n\tB bool\n\tC bool `argum:\"-c\"`\n\tD bool\n\tE bool \n}\nargum.MustParse(\u0026args)\n```\n\nThis options can be specified as `./example -abcde`, and each of listed will be set to `true`\n\n### Internal structs and `oneof` keyword\n\n```go\nvar args struct {\n\tCommand Commands `argum:\"req,oneof\" help:\"select main command\"`\n\n\tListen *Echo `help:\"optional internal struct\"`\n\n\tValue string `argum:\"pos\" help:\"Some string value\"`\n\tDebug bool   `argum:\"-d,--debug\" help:\"Enable debug mode\"`\n}\n\ntype Commands struct {\n\tPing *Ping  `help:\"some ping\"`\n\tEcho *Echo  `help:\"open local port\"`\n\tStr  string `argum:\"pos\" help:\"simple string value instead struct\"`\n}\n\ntype Ping struct {\n\tIP    string `argum:\"req,pos\" help:\"ip address\"`\n\tCount int    `argum:\"-c\" help:\"count of packets\"`\n}\n\ntype Echo struct {\n\tPort int `argum:\"req,pos\" help:\"port number\"`\n}\n\n```\n\nKeyword `oneof` is means user should chose only one of nested fields. These example structures will provide next command lines: \n\n\t./example ping 127.0.0.1\n\t./example -d ping 127.0.0.1\n\t./example ping 127.0.0.1 -c4\n\t./example ping 127.0.0.1 -c4 listen 8000\n\n\t./example echo 8080\n\t./example echo 8080 -d\n\t./example echo 8080 listen 8000\n\n\n### Embedding structs\n\n```go\nvar args struct {\n\tPing `argum:\"emb\"`\n}\n\ntype Ping struct {\n\tIP string `argum:\"pos,req\"`\n\tCount int    `argum:\"-c\" help:\"count of packets\"`\n}\n```\n\nKeyword `emb` or `embedded` indicates that the structure name should be ignored. These example will provide next command lines:\n\n\t./example 127.0.0.1\n\t./example 127.0.0.1 -c 4\n\n\n### Help and Usage output\n\n```go\nvar args struct {\n\tA bool `help:\"a option, enable something\"`\n\tB bool `help:\"if true, then something will happen\"`\n\tC bool `help:\"c enable something\"`\n\n\tS      string `argum:\"req,str0|str1|str2\" help:\"required value for something\"`\n\tString string `help:\"set string value\"`\n\n\tArg        string `argum:\"-a\" help:\"optional you may set Arg variable\"`\n\tOneMoreArg string `argum:\"-o,--onemore\" default:\"some-value\" help:\"one more arg\"`\n\n\tPos string `argum:\"pos,debug|normal|fast\" default:\"normal\" help:\"mode\"`\n}\nargum.Version = \"example version 0.1.2\"\nargum.MustParse(\u0026args)\n```\n\n```\nusage: example [-abc] -s=[str0|str1|str2] [--string=\u003cs\u003e] [-a=\u003cs\u003e] [-o=\u003cs\u003e] [debug|normal|fast]\n\npositional:\n  pos                     mode [default: normal] [debug|normal|fast]\n\noptions:\n  -a                      a option, enable something\n  -b                      if true, then something will happen\n  -c                      c enable something\n  -s=[str0|str1|str2]     required value for something [str0|str1|str2]\n      --string=\u003cs\u003e        set string value\n  -a=\u003cs\u003e                  optional you may set Arg variable\n  -o, --onemore=\u003cs\u003e       one more arg [default: some-value]\n  -h, --help              display this help and exit\n      --version           display version and exit\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsg3des%2Fargum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsg3des%2Fargum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsg3des%2Fargum/lists"}