feat: add -c/--config runtime arg for config file path - #396
Open
TurtIeSocks wants to merge 1 commit into
Open
Conversation
Golbat always read config.toml from the working directory. Add a -c/--config flag so the file can live anywhere, which matters for packaged installs (/etc/golbat/config.toml) and for running several instances from one binary. Omitting the flag keeps the previous behavior: config.toml in the working directory, and a missing file is fine because the whole config can come from GOLBAT_* environment variables. A path passed explicitly must exist, otherwise startup fails rather than silently booting on defaults. The old missing-file check compared the error string against a hardcoded "open config.toml: no such file or directory", which would stop matching as soon as the path became a variable. Replaced with errors.Is(err, fs.ErrNotExist). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Golbat has always read
config.tomlfrom the working directory. This adds a-c/--configflag so the file can live somewhere else, which matters for packaged installs (/etc/golbat/config.toml) and for running more than one instance from a single binary.Both spellings work, since Go's
flagpackage treats-xand--xthe same:Behavior
Without the flag nothing changes:
config.tomlin the working directory, and a missing file there is still fine, because the whole config can come fromGOLBAT_*environment variables instead.A path passed explicitly has to exist. If it doesn't, startup fails instead of quietly falling back to defaults. A typo'd
--configthat boots Golbat on stock settings looks alive but points at the wrong database, which is the worse of the two failures.The old missing-file check
ReadConfigdetected a missing file by comparing the error text against a hardcoded"open config.toml: no such file or directory". That stops matching as soon as the path becomes a variable, so every missing custom config would have printed a spurious warning. It is nowerrors.Is(err, fs.ErrNotExist).Testing
config/reader_test.gocovers the three cases: a missing default path is not an error, a missing explicit path is, and an explicit file actually loads.go build -tags go_json ./...cleango test -tags go_json ./config/ .both packages okgolangci-lint run ./config/... .0 issues-hlists both flags;-c /nope.tomland--config /nope.tomlboth fail withconfig file /nope.toml not found🤖 Generated with Claude Code