Skip to content

feat: make template provider URLs configurable via environment variables#5

Merged
bakayu merged 6 commits into
bakayu:masterfrom
Ashmit-Singh-Gogia:master
Jun 18, 2026
Merged

feat: make template provider URLs configurable via environment variables#5
bakayu merged 6 commits into
bakayu:masterfrom
Ashmit-Singh-Gogia:master

Conversation

@Ashmit-Singh-Gogia

Copy link
Copy Markdown
Contributor

Description

This PR resolves the issue regarding hardcoded provider URLs. It allows users to override the default Toptal and GitHub API URLs using shell environment variables. This ensures lq can be seamlessly used behind strict corporate firewalls, proxies, or with private/custom internal template servers.

What Changed

  • Centralized Configuration: Created a new internal/config package to act as the single source of truth for loading and validating environment variables.
  • New Environment Variables: Added support for:
    • LQ_GITIGNORE_LIST_URL
    • LQ_GITIGNORE_GET_URL
    • LQ_LICENSE_LIST_URL
    • LQ_LICENSE_GET_URL
  • Fail-Fast URL Validation: The CLI now validates the structure of the provided URLs (safely handling the %s placeholder) immediately on startup. If a malformed URL is detected, it cleanly exits with 1 and a descriptive message before rendering the TUI.
  • Dependency Injection: Refactored the provider constructors (NewGitignoreProvider, NewLicenseProvider) to accept config arguments, decoupling them from the environment and making them highly testable.
  • Safety Checks: Added an os.Stat check before writing files to prevent silent obliteration of a user's existing .gitignore or LICENSE.
  • Clean CLI Error Handling: Replaced standard log.Fatal panics with fmt.Fprintf(os.Stderr) and os.Exit(1) to prevent messy timestamps from leaking into the TUI.

How to Test

  1. Run lq with no environment variables -> Proceeds normally with default URLs.
  2. Run export LQ_GITIGNORE_LIST_URL="not-a-valid-url" -> Fails fast on startup with a clean error message.
  3. Run export LQ_GITIGNORE_LIST_URL="https://custom.company.com/api/gitignores" -> Successfully overrides the default endpoint.

Resolves #3

@bakayu bakayu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves the loading in a different template provider, but the problem of the schema of different providers being different still exists.

Comment thread internal/provider/gitignore.go Outdated
Comment thread internal/config/config.go Outdated
// Load reads configuration from environment variables, falling back to defaults if not set.
func Load() (*Config, error) {
cfg := &Config{
GitignoreListURL: getEnv("LQ_GITIGNORE_LIST_URL", "https://www.toptal.com/developers/gitignore/api/list?format=json"),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could move the https://www.toptal.com/developers/gitignore/api/list?format=json to a const, see: https://github.com/bakayu/lq/pull/5/changes#r3428698374

Comment thread internal/provider/license.go Outdated
@bakayu

bakayu commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Also, fix the lint and build errors

@bakayu bakayu merged commit 2cb435b into bakayu:master Jun 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Make Gitignore and License Provider URLs Configurable via Environment Variables

2 participants