{"id":25961692,"url":"https://github.com/ttab/clitools","last_synced_at":"2026-05-11T02:53:17.587Z","repository":{"id":273902832,"uuid":"921256248","full_name":"ttab/clitools","owner":"ttab","description":"Helpers for building cli tools","archived":false,"fork":false,"pushed_at":"2025-01-23T16:22:57.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-01-23T17:28:01.996Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ttab.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":"2025-01-23T16:19:49.000Z","updated_at":"2025-01-23T16:22:41.000Z","dependencies_parsed_at":"2025-01-23T17:28:26.114Z","dependency_job_id":"d0e3eb59-60c8-401a-b218-28abf7962600","html_url":"https://github.com/ttab/clitools","commit_stats":null,"previous_names":["ttab/clitools"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttab%2Fclitools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttab%2Fclitools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttab%2Fclitools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttab%2Fclitools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ttab","download_url":"https://codeload.github.com/ttab/clitools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241912991,"owners_count":20041457,"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":[],"created_at":"2025-03-04T19:41:00.489Z","updated_at":"2026-05-11T02:53:17.578Z","avatar_url":"https://github.com/ttab.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CLI tools\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/ttab/clitools.svg)](https://pkg.go.dev/github.com/ttab/clitools)\n\nHelpers for building Elephant CLI tools. Handles environment configuration, service endpoint resolution, and OIDC authentication so that individual CLI applications don't have to.\n\n## Configuring an environment\n\nBefore a CLI tool can authenticate or call services, the target environment needs to be configured. The package provides a `configure` CLI command (via `ConfigureCliCommands`) that can be embedded in any application built with [urfave/cli](https://github.com/urfave/cli):\n\n```bash\n# Set the base URL for the environment. Service endpoints are derived from it.\nmyapp --env=prod configure --base-url=https://tt.ecms.se --oidc=https://login.tt.se/realms/elephant\n\n# Individual endpoints can be overridden when a service doesn't follow the\n# standard naming convention.\nmyapp --env=prod configure --endpoint=chrome=https://tt.se/elephant\n```\n\nSetting a base URL like `https://tt.ecms.se` means that service endpoints are constructed on the fly:\n\n| Service    | Derived URL                        |\n|------------|------------------------------------|\n| repository | `https://repository.api.tt.ecms.se` |\n| index      | `https://index.api.tt.ecms.se`      |\n| chrome     | `https://tt.ecms.se/elephant`       |\n| ...        | `https://{name}.api.tt.ecms.se`     |\n\nThe \"chrome\" endpoint is special-cased to `{base URL}/elephant`. All other endpoints follow the pattern `{scheme}://{name}.api.{host}`.\n\nExplicit endpoints (set with `--endpoint`) always take precedence over endpoints derived from the base URL.\n\n## Endpoint resolution\n\nApplication code retrieves endpoints through the `ConfigurationHandler`:\n\n```go\nhandler, err := clitools.NewConfigurationHandler(\"myapp\", clitools.DefaultApplicationID, \"prod\")\n\n// Look up a specific endpoint.\nrepoURL, ok := handler.GetEndpoint(\"repository\")\n\n// Get all known endpoints (base URL derived + explicit overrides).\nallEndpoints := handler.GetEndpoints()\n```\n\n`GetEndpoint` checks explicit endpoints first, then falls back to constructing the URL from the base URL. Any service name can be resolved this way, so new services work without reconfiguration.\n\n## Authentication\n\nThe package supports two OIDC flows:\n\n**Authorization code with PKCE** (interactive CLI usage): `GetAccessToken` opens a browser for the user to log in and starts a temporary local HTTP server to receive the callback. Tokens are cached and reused until they expire.\n\n**Client credentials** (service-to-service): `GetClientAccessToken` returns an `oauth2.TokenSource` for the given client ID and secret.\n\nSee the [example in the Go docs](https://pkg.go.dev/github.com/ttab/clitools#example-package) for a complete usage example.\n\n## Configuration storage\n\nConfiguration is stored per environment under `$XDG_CONFIG_HOME/elephant-clitools/{environment}/` (or the platform-appropriate [user configuration directory](https://pkg.go.dev/os#UserConfigDir), e.g. `~/.config/elephant-clitools/{environment}/` on Linux).\n\nEach environment directory contains:\n- `config.json` -- OIDC settings, base URL, and endpoint overrides. Shared across all applications using the same environment.\n- `tokens.json` -- cached access tokens, keyed by application name.\n\nFile system locking ensures that concurrent CLI processes don't corrupt the configuration.\n\n## Environment variable loading\n\n`UserConfigDir()` gives preference to `XDG_CONFIG_HOME`, letting users on any OS specify a Linux-style user config location. If `XDG_CONFIG_HOME` is empty it behaves just like `os.UserConfigDir()`.\n\n`LoadEnv()` loads any `.env` file (override the path by setting `DOT_ENV`) in the current directory and `{user config dir}/{app}/config.env` if they exist. Already-set variables are not overridden, and `.env` takes precedence over `config.env`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttab%2Fclitools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fttab%2Fclitools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttab%2Fclitools/lists"}