Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration improvements - Environment variable support, docs, CLI flag tweaks #138

Merged
merged 2 commits into from
Apr 24, 2024

Conversation

Maelkum
Copy link
Collaborator

@Maelkum Maelkum commented Apr 9, 2024

This PR makes a number of changes to the config loading.

Environment Variable Support

We can now use environment variables to set config options. Rules when multiple options are set:

  1. CLI flags rule everything
  2. Config file - we specify config file on the CLI too, so it takes precedence over
  3. Environment variables
  4. CLI flag default values

Rules for environment variable naming - if the config option is worker=>runtime-path, then the environment variable is B7S_Worker_RuntimePath

CLI flags are defined in the config struct itself

Having CLI flags defined in a single place makes it easier to manage, has a single source of truth and makes it easier to see the connection between the config file structure and the corresponding CLI flag.

CLI flags also load their defaults from the package-level default config variable (more transparent what the defaults are).

Generating documentation from the code

Added a CLI tool (generate local HTML or serve via HTTP) to generate documentation from the code. The documentation showcases the config structure, config option type, CLI flags, environment variables and defaults for all options.

Sample of generated docs look can be seen here

@Maelkum Maelkum requested a review from dmikey April 9, 2024 13:30
@Maelkum Maelkum self-assigned this Apr 9, 2024
Fix path handling for windows in config tests

Add JSON tags and make field naming more consistent

Generate CLI flags from struct

Flat map is generated on the fly (fewer allocations)

Renames and minor tweaks

Add CLI flag descriptions

Rename file

Minor restructuring

Minor tweaks

First draft of a documentation generation tool

Adding templ code and some styling info

Style tweaks

Add option to disable file embedding

Promote documentation code

Add a warning for using tabs in struct tags
@Maelkum Maelkum force-pushed the config-env-support branch from 5006c74 to 8929f40 Compare April 12, 2024 11:20
@dmikey dmikey merged commit 5369285 into main Apr 24, 2024
2 checks passed
@dmikey dmikey deleted the config-env-support branch April 24, 2024 18:55
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.

2 participants