{"id":16037844,"url":"https://github.com/joseluisq/cline","last_synced_at":"2026-01-03T14:22:43.460Z","repository":{"id":56386779,"uuid":"306161698","full_name":"joseluisq/cline","owner":"joseluisq","description":"A fast and lightweight CLI package for Go without external dependencies.","archived":false,"fork":false,"pushed_at":"2023-06-20T21:10:40.000Z","size":109,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-22T14:22:59.686Z","etag":null,"topics":["cli","command-line-tool","golang","golang-package"],"latest_commit_sha":null,"homepage":"https://git.io/Cline","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/joseluisq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-10-21T22:23:34.000Z","updated_at":"2022-07-15T17:08:15.000Z","dependencies_parsed_at":"2023-10-12T07:30:37.970Z","dependency_job_id":null,"html_url":"https://github.com/joseluisq/cline","commit_stats":{"total_commits":54,"total_committers":1,"mean_commits":54.0,"dds":0.0,"last_synced_commit":"6d07d806b8adbc2ffaf76ddf328529d91efe8355"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joseluisq%2Fcline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joseluisq%2Fcline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joseluisq%2Fcline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joseluisq%2Fcline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joseluisq","download_url":"https://codeload.github.com/joseluisq/cline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247397312,"owners_count":20932504,"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-tool","golang","golang-package"],"created_at":"2024-10-08T22:21:47.191Z","updated_at":"2026-01-03T14:22:43.455Z","avatar_url":"https://github.com/joseluisq.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CLIne [![devel](https://github.com/joseluisq/cline/actions/workflows/devel.yml/badge.svg)](https://github.com/joseluisq/cline/actions/workflows/devel.yml) [![codecov](https://codecov.io/gh/joseluisq/cline/graph/badge.svg?token=LisSjmXpcx)](https://codecov.io/gh/joseluisq/cline) [![Go Report Card](https://goreportcard.com/badge/github.com/joseluisq/cline)](https://goreportcard.com/report/github.com/joseluisq/cline) [![PkgGoDev](https://pkg.go.dev/badge/github.com/joseluisq/cline)](https://pkg.go.dev/github.com/joseluisq/cline)\n\n\u003e A fast and lightweight CLI package for Go without external dependencies.\n\n## Features\n\n- No external dependencies more than few [Go's stdlib](https://golang.org/pkg/#stdlib) ones.\n- Compact but concise API.\n- Global flags support.\n- Single-level commands support only.\n- `bool`, `int`, `string` and `[]string` flag's data types.\n- Flag aliases and default values support.\n- Optional environment variable names for flags.\n- Convenient contexts for function handlers (global and command flags)\n- Context built-in types conversion API for `bool`, `int`, `string` and `[]string` flag values.\n- Convenient API to detect provided (passed) flags with thier properties.\n- Strict UTF-8 for arguments and alphanumeric ASCII for flags and commands.\n- POSIX-compliant support is intentionally partial (see the limitations below).\n- Restrict the maximum argument length and maximum number of arguments provided.\n- Support for flags termination via `--` to provide further positional arguments (tail args).\n- Same repeated flag arguments use the last value provided.\n- Automatic `--help` (`-h`) flag for global flags and commands.\n- Automatic `--version` (`-v`) flag with relevant information like app version, Go version, build datetime and OS/Arch and commit.\n\n## Limitations\n\nThe following POSIX features are intentionally NOT supported:\n\n- Short single-dash combined flags (e.g. `-abc` for `-a -b -c`).\n- Short single-dash flags with equal sign (e.g. `-f=value` or `--file=value`).\n- Single hyphen to denote standard input or output (e.g. `myapp -`).\n- Optional whitespace between flags and their values (e.g. `-vfoo` for `-v foo`).\n\nPlease see [POSIX-compliant support (#3)](https://github.com/joseluisq/cline/issues/3) for details.\n\n## Usage\n\nAPI definition example:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/joseluisq/cline/app\"\n\t\"github.com/joseluisq/cline/flag\"\n\t\"github.com/joseluisq/cline/handler\"\n)\n\n// App values passed at compile time for --version flag\n// See \"Makefile \u003e build\"\nvar (\n\tversion     string = \"devel\"\n\tbuildTime   string\n\tbuildCommit string\n)\n\nfunc main() {\n\tap := app.New()\n\tap.Name = \"enve\"\n\tap.Summary = \"Run a program in a modified environment using .env files\"\n\tap.Version = version\n\tap.BuildTime = buildTime\n\tap.BuildCommit = buildCommit\n\t// Global App flags\n\tap.Flags = []flag.Flag{\n\t\tflag.FlagString{\n\t\t\tName:    \"file\",\n\t\t\tSummary: \"Load environment variables from a file path\",\n\t\t\tValue:   \".env\",\n\t\t\tAliases: []string{\"f\"},\n\t\t},\n\t\tflag.FlagBool{\n\t\t\tName:    \"verbose\",\n\t\t\tSummary: \"Enable more verbose info\",\n\t\t\tValue:   false,\n\t\t\tAliases: []string{\"V\"},\n\t\t\tEnvVar:  \"ENV_VERBOSE\",\n\t\t},\n\t}\n\t// App commands\n\tap.Commands = []app.Cmd{\n\t\t{\n\t\t\tName:    \"info\",\n\t\t\tSummary: \"Show command information\",\n\t\t\tFlags: []flag.Flag{\n\t\t\t\tflag.FlagInt{\n\t\t\t\t\tName:    \"trace\",\n\t\t\t\t\tSummary: \"Enable tracing mode\",\n\t\t\t\t\tValue:   10,\n\t\t\t\t\tAliases: []string{\"t\"},\n\t\t\t\t},\n\t\t\t\tflag.FlagBool{\n\t\t\t\t\tName:    \"detailed\",\n\t\t\t\t\tSummary: \"Enable info details\",\n\t\t\t\t\tValue:   true,\n\t\t\t\t\tAliases: []string{\"d\"},\n\t\t\t\t},\n\t\t\t},\n\t\t\t// Specific command handler for its flags\n\t\t\tHandler: func(ctx *app.CmdContext) error {\n\t\t\t\tfmt.Printf(\"Cmd `%s` executed!\\n\", ctx.Cmd.Name)\n\t\t\t\tfmt.Printf(\"App Flag `file` opted: `%s`\\n\", ctx.AppContext.Flags().Value(\"file\"))\n\n\t\t\t\ttrace, err := ctx.Flags.Int(\"trace\")\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\ti, err := trace.Value()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tfmt.Printf(\"Cmd Flag `trace` opted: `%d` (%T)\\n\", i, i)\n\n\t\t\t\tdetailed, err := ctx.Flags.Bool(\"detailed\")\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\td, err := detailed.Value()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tfmt.Printf(\"Cmd Flag `detailed` opted: `%v` (%T)\\n\", d, d)\n\n\t\t\t\tfmt.Printf(\"Cmd Tail arguments: %#v\\n\", ctx.TailArgs)\n\t\t\t\treturn nil\n\t\t\t},\n\t\t},\n\t}\n\t// App handler for flags\n\tap.Handler = func(ctx *app.AppContext) error {\n\t\tfmt.Printf(\"App `%s` executed!\\n\", ctx.App().Name)\n\t\tfmt.Printf(\"App Tail arguments: %#v\\n\", ctx.TailArgs)\n\n\t\tif f, err := ctx.Flags().StringSlice(\"file\"); err == nil {\n\t\t\tfmt.Printf(\"App Flag `file` opted: `%v`\\n\", f.Value())\n\t\t}\n\n\t\tif v, err := ctx.Flags().Bool(\"verbose\"); err == nil {\n\t\t\tb, _ := v.Value()\n\t\t\tfmt.Printf(\"App Flag `verbose` opted: `%v`\\n\", b)\n\t\t}\n\n\t\treturn nil\n\t}\n\tif err := handler.New(ap).Run(os.Args); err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n}\n```\n\nOutput example:\n\n```sh\n$ go run examples/main.go -h\n# enve 0.0.0\n# Run a program in a modified environment using .env files\n\n# USAGE:\n#    enve [OPTIONS] COMMAND\n#\n# OPTIONS:\n#       -f --file      Load environment variables from a file path.\n#                      Some new line description\n#                      Another new line description. [default: .env]\n#    -b,-z --int       Int value [default: 5]\n#       -V --verbose   Enable more verbose info [default: true] [env: ENV_VERBOSE]\n#       -h --help      Prints help information\n#       -v --version   Prints version information\n#\n# COMMANDS:\n#    info   Show command information\n#\n# Run 'enve COMMAND --help' for more information on a command\n\n$ go run examples/main.go -v\n# Version:       0.0.0\n# Go version:    go1.24.5\n# Built:         2025-09-15T16:09:24\n# Commit:        9061c4d\n```\n\nMore details on [examples/main.go](./examples/main.go)\n\n## Contributions\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in current work by you, as defined in the Apache-2.0 license, shall be dual licensed as described below, without any additional terms or conditions.\n\nFeel free to send some [Pull request](https://github.com/joseluisq/cline/pulls) or [issue](https://github.com/joseluisq/cline/issues).\n\n## License\n\nThis work is primarily distributed under the terms of both the [MIT license](LICENSE-MIT) and the [Apache License (Version 2.0)](LICENSE-APACHE).\n\n© 2020-present [Jose Quintana](https://github.com/joseluisq)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoseluisq%2Fcline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoseluisq%2Fcline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoseluisq%2Fcline/lists"}