From dc45c55e13b8282ba1f5f053974eb857d3c03be9 Mon Sep 17 00:00:00 2001 From: d3vyce Date: Mon, 6 Jul 2026 11:58:20 -0400 Subject: [PATCH] feat: allow default context via FIXTURES_CONTEXT env var for fixtures load --- docs/module/cli.md | 14 ++++++++++++++ src/fastapi_toolsets/cli/commands/fixtures.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/module/cli.md b/docs/module/cli.md index c80a7367..a3933c3c 100644 --- a/docs/module/cli.md +++ b/docs/module/cli.md @@ -68,6 +68,20 @@ manager fixtures --help ╰──────────────────────────────────────────────────────────────────────────────────╯ ``` +### `fixtures load` + +```bash +manager fixtures load [CONTEXTS]... [--strategy merge|insert|skip_existing] [--dry-run] +``` + +`CONTEXTS` defaults to `Context.BASE` when omitted, and can also be set via the `FIXTURES_CONTEXT` environment variable, handy for CI/deploy scripts that shouldn't need an explicit argument per environment: + +```bash +FIXTURES_CONTEXT=testing manager fixtures load +``` + +An explicit CLI argument always takes precedence over the environment variable. + ## Custom CLI You can extend the CLI by providing your own Typer app. The `manager` entry point will merge your app's commands with the built-in ones: diff --git a/src/fastapi_toolsets/cli/commands/fixtures.py b/src/fastapi_toolsets/cli/commands/fixtures.py index c479a9bc..da4e3b1d 100644 --- a/src/fastapi_toolsets/cli/commands/fixtures.py +++ b/src/fastapi_toolsets/cli/commands/fixtures.py @@ -57,7 +57,7 @@ async def load( ctx: typer.Context, contexts: Annotated[ list[str] | None, - typer.Argument(help="Contexts to load."), + typer.Argument(help="Contexts to load.", envvar="FIXTURES_CONTEXT"), ] = None, strategy: Annotated[ LoadStrategy,