{"id":28237223,"url":"https://github.com/just-do-halee/opt","last_synced_at":"2025-06-10T15:30:29.985Z","repository":{"id":63665573,"uuid":"562846191","full_name":"just-do-halee/opt","owner":"just-do-halee","description":"Opt is a package for building an organized CLI app in Go","archived":false,"fork":false,"pushed_at":"2022-12-03T13:17:46.000Z","size":59,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-19T00:17:56.223Z","etag":null,"topics":["cli","command-line","go","golang","golang-library","opt"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/just-do-halee.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["just-do-halee"]}},"created_at":"2022-11-07T11:36:29.000Z","updated_at":"2022-11-23T11:36:46.000Z","dependencies_parsed_at":"2022-11-23T13:36:17.779Z","dependency_job_id":null,"html_url":"https://github.com/just-do-halee/opt","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/just-do-halee%2Fopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/just-do-halee%2Fopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/just-do-halee%2Fopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/just-do-halee%2Fopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/just-do-halee","download_url":"https://codeload.github.com/just-do-halee/opt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/just-do-halee%2Fopt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259100992,"owners_count":22805182,"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":["cli","command-line","go","golang","golang-library","opt"],"created_at":"2025-05-19T00:17:52.941Z","updated_at":"2025-06-10T15:30:29.974Z","avatar_url":"https://github.com/just-do-halee.png","language":"Go","funding_links":["https://github.com/sponsors/just-do-halee"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./.github/logo.png\" alt=\"go-arg\" height=\"170px\"\u003e\n  \u003ch1\u003eOPT\u003c/h1\u003e\n  \u003cp\u003eOpt is a package for building an organized CLI app in Go.\u003c/p\u003e\n  \u003cbr/\u003e\n\u003c/div\u003e\n\n```shell\ngo get -u github.com/just-do-halee/opt@latest\n```\n\n[![CI][ci-badge]][ci-url]\n[![Go Reference](https://pkg.go.dev/badge/github.com/just-do-halee/opt.svg)](https://pkg.go.dev/github.com/just-do-halee/opt)\n[![Licensed][license-badge]][license-url]\n[![Twitter][twitter-badge]][twitter-url]\n\n[ci-badge]: https://github.com/just-do-halee/opt/actions/workflows/ci.yml/badge.svg\n[license-badge]: https://img.shields.io/github/license/just-do-halee/opt?color=blue\n[twitter-badge]: https://img.shields.io/twitter/follow/do_halee?style=flat\u0026logo=twitter\u0026color=4a4646\u0026labelColor=333131\u0026label=just-do-halee\n[ci-url]: https://github.com/just-do-halee/opt/actions\n[twitter-url]: https://twitter.com/do_halee\n[license-url]: https://github.com/just-do-halee/opt\n\n| [Examples](./examples/) | [Latest Note](./CHANGELOG.md) |\n\n```go\ntype file string\n\ntype Textify struct {\n\tInput   opt.Argument[file] `msg:\"Input path\"`\n\tOutput  opt.Option[file]   `msg:\"Output path\" opt:\"s,l\"`\n\tVerbose opt.Option[int]    `msg:\"Verbosity level -vv..\" opt:\"s,l,o\"`\n\tSilent  opt.Option[bool]   `msg:\"Silent mode\" opt:\"s,l\"`\n\tCat     opt.Command[cat]   `msg:\"Print file contents\"`\n\n\tHelp        opt.Option[opt.Help]  `opt:\"s,l\"`\n\tHelpCommand opt.Command[opt.Help] `rename:\"help\"`\n}\n\nfunc (o *Textify) Before() error {\n\to.Output.Set(\"./output.txt\")\n\to.Verbose.Set(2)\n\to.Silent.Set(false)\n\treturn nil\n}\n\nfunc (o *Textify) After() error {\n\tvar err error\n\n\terr = o.Input.Validate(opt.IsFile[file])\n\tif err != nil {\n\t\treturn err\n\t}\n\terr = o.Verbose.Validate(opt.IsMinMax(0, 3))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\nfunc (o *Textify) Run() error {\n\tinput := o.Input.Get()\n\toutput := o.Output.Get()\n\n\tverbose := o.Verbose.Get()\n\tsilent := o.Silent.Get()\n\n\tif verbose \u003e 0 \u0026\u0026 !silent {\n\t\tlog.Println(\"Copying file:\", input, \"to\", output)\n\t}\n\n\tbytesRead, err := ioutil.ReadFile(string(input))\n\tif err != nil {\n\t\treturn err\n\t}\n\terr = ioutil.WriteFile(string(output), bytesRead, 0644)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\n// ----------------------------------------------\n\ntype cat struct {\n\tParent opt.Parent[Textify]\n\tFile   opt.Argument[file] `msg:\"File to print\"`\n\tLen    opt.Option[uint]   `msg:\"Length of output\" opt:\"s,l\"`\n}\n\nfunc (o *cat) Before() error {\n\to.Len.Set(10)\n\treturn nil\n}\n\nfunc (o *cat) After() error {\n\treturn o.File.Validate(opt.IsFile[file])\n}\n\nfunc (o *cat) Run() error {\n\tp := o.Parent.Get()\n\tverbose := p.Verbose.Get()\n\tsilent := p.Silent.Get()\n\n\tprintln := func(a ...any) {\n\t\tif verbose \u003e 0 \u0026\u0026 !silent {\n\t\t\tlog.Println(a...)\n\t\t}\n\t}\n\n\tfile := o.File.Get()\n\n\tprintln(\"Opening file:\", file)\n\tf, err := os.OpenFile(string(file), os.O_RDONLY, 0)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\n\tprintln(\"\u003c---------Reading contents---------\u003e\")\n\t// print file contents\n\tbuf := bufio.NewReader(f)\n\tfor i := uint(0); i \u003c o.Len.Get(); i++ {\n\t\tline, err := buf.ReadString('\\n')\n\t\tif err != nil {\n\t\t\tbreak\n\t\t}\n\t\tfmt.Print(line)\n\t}\n\tprintln(\"\u003e---------End of contents----------\u003c\")\n\treturn nil\n}\n```\n\n```go\nfunc main() {\n\terr :=\n\t\topt.Args().\n\t\t\tVersion(\"v0.1.0\").\n\t\t\tAuthor(\"just-do-halee \u003cjust.do.halee@gmail.com\u003e\").\n\t\t\tAbout(\"This is a CLI app program.\").\n\t\t\tBuild(new(Textify))\n\n\tif err != nil {\n\t\tfmt.Print(err)\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjust-do-halee%2Fopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjust-do-halee%2Fopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjust-do-halee%2Fopt/lists"}