Skip to content

feat: make environment variables opt-in via option(env=...) - #7

Merged
bhirsz merged 1 commit into
mainfrom
feat/opt-in-env
Aug 28, 2026
Merged

feat: make environment variables opt-in via option(env=...)#7
bhirsz merged 1 commit into
mainfrom
feat/opt-in-env

Conversation

@bhirsz

@bhirsz bhirsz commented Aug 28, 2026

Copy link
Copy Markdown
Member

Stacked on #6 (base branch feat/cli-config-toggles).

Makes reading from the environment opt-in per option instead of an implicit, class-wide behaviour.

  • @option(env=True) — reads a variable whose name is generated from the class env_var_template (default "{name}_{option}", formatted with the tool name + attribute name and upper-cased, e.g. MYTOOL_LOG).
  • @option(env="NAME") — sets an explicit variable name, used verbatim.
  • @option (default env=False) — never read from the environment.

Adds the env_var_template class attribute so tools can customise generated names.

Breaking changes

  • The envvar= argument of @option is removed → use env="NAME".
  • The auto_env_vars class attribute is removed → add env=True to each option that should read the environment.

Validation

ruff / ruff format --check / mypy / pytest all green (168 tests); verified MYTOOL_CONSOLE and GREETER_WHO end-to-end against the demo and example.

Review/merge #6 first; this PR's diff will simplify against main once #6 lands.

@bhirsz bhirsz changed the title feat!: make environment variables opt-in via option(env=...) feat: make environment variables opt-in via option(env=...) Aug 28, 2026
Base automatically changed from feat/cli-config-toggles to main August 28, 2026 12:46
Environment reading is now opt-in per option instead of an implicit,
class-wide behaviour:

* @option(env=True) reads a variable whose name is generated from the
  class env_var_template (default "{name}_{option}" upper-cased).
* @option(env="NAME") sets an explicit variable name verbatim.
* @option (default env=False) is never read from the environment.

Adds the env_var_template class attribute so tools can customise the
generated names.

Migration (pre-1.0, no stability guarantees yet): the envvar= argument
of @option and the auto_env_vars class attribute are removed; declare
env= on each option that should read the environment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bhirsz
bhirsz merged commit daa5773 into main Aug 28, 2026
8 checks passed
@bhirsz
bhirsz deleted the feat/opt-in-env branch August 28, 2026 12:54
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