Skip to content

feat: add -c/--config runtime arg for config file path - #396

Open
TurtIeSocks wants to merge 1 commit into
mainfrom
c/config-file-runtime-arg-ac0fa1
Open

feat: add -c/--config runtime arg for config file path#396
TurtIeSocks wants to merge 1 commit into
mainfrom
c/config-file-runtime-arg-ac0fa1

Conversation

@TurtIeSocks

Copy link
Copy Markdown
Contributor

Golbat has always read config.toml from the working directory. This adds a -c / --config flag 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 flag package treats -x and --x the same:

golbat -c /etc/golbat/config.toml
golbat --config /etc/golbat/config.toml

Behavior

Without the flag nothing changes: config.toml in the working directory, and a missing file there is still fine, because the whole config can come from GOLBAT_* 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 --config that 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

ReadConfig detected 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 now errors.Is(err, fs.ErrNotExist).

Testing

config/reader_test.go covers 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 ./... clean
  • go test -tags go_json ./config/ . both packages ok
  • golangci-lint run ./config/... . 0 issues
  • Built binary: -h lists both flags; -c /nope.toml and --config /nope.toml both fail with config file /nope.toml not found

🤖 Generated with Claude Code

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>
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.

1 participant