Skip to content

Commit 7e3b4b8

Browse files
committed
refactor: extract CLI env helper
1 parent 2a8e380 commit 7e3b4b8

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

tests/test_cli_config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,37 @@
33
import pytest
44

55
from typetreeflow import cli
6+
from typetreeflow.cli_config import _env_value as config_env_value
67
from typetreeflow.cli_config import _normalize_command_argv as config_normalize_argv
78

89

910
def test_cli_normalize_command_argv_compatibility_export():
1011
assert cli._normalize_command_argv is config_normalize_argv
1112

1213

14+
def test_cli_env_value_compatibility_export():
15+
assert cli._env_value is config_env_value
16+
17+
18+
def test_env_value_returns_stripped_set_value(monkeypatch):
19+
monkeypatch.setenv("TYPETREEFLOW_EMAIL", " user@example.org ")
20+
21+
assert cli._env_value("TYPETREEFLOW_EMAIL") == "user@example.org"
22+
assert config_env_value("TYPETREEFLOW_EMAIL") == "user@example.org"
23+
24+
25+
def test_env_value_returns_none_for_unset_or_blank_value(monkeypatch):
26+
monkeypatch.delenv("TYPETREEFLOW_EMAIL", raising=False)
27+
28+
assert cli._env_value("TYPETREEFLOW_EMAIL") is None
29+
assert config_env_value("TYPETREEFLOW_EMAIL") is None
30+
31+
monkeypatch.setenv("TYPETREEFLOW_EMAIL", " ")
32+
33+
assert cli._env_value("TYPETREEFLOW_EMAIL") is None
34+
assert config_env_value("TYPETREEFLOW_EMAIL") is None
35+
36+
1337
def test_normalize_command_aliases_preserves_existing_rewrites():
1438
assert config_normalize_argv(["doctor", "--strict"]) == (
1539
["--doctor", "--doctor-strict"],

typetreeflow/cli.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import csv
44
import logging
5-
import os
65
import shutil
76
import sys
87
from dataclasses import dataclass, field, replace
@@ -16,7 +15,7 @@
1615
write_completion_summary,
1716
)
1817
from typetreeflow.completion_gaps import generate_completion_gap_reports
19-
from typetreeflow.cli_config import _normalize_command_argv
18+
from typetreeflow.cli_config import _env_value, _normalize_command_argv
2019
from typetreeflow.cli_parser import build_parser
2120
from typetreeflow.config import AppConfig, ensure_real_action_allowed
2221
from typetreeflow.delivery import package_results
@@ -317,14 +316,6 @@ def parse_args(argv: list[str] | None = None) -> AppConfig:
317316
)
318317

319318

320-
def _env_value(name: str) -> str | None:
321-
value = os.environ.get(name)
322-
if value is None:
323-
return None
324-
stripped = value.strip()
325-
return stripped or None
326-
327-
328319
def main(
329320
argv: list[str] | None = None,
330321
download_runner=None,

typetreeflow/cli_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
from __future__ import annotations
22

3+
import os
34
import sys
45

56

7+
def _env_value(name: str) -> str | None:
8+
value = os.environ.get(name)
9+
if value is None:
10+
return None
11+
stripped = value.strip()
12+
return stripped or None
13+
14+
615
def _normalize_command_argv(
716
argv: list[str] | None,
817
) -> tuple[list[str] | None, bool, bool]:

0 commit comments

Comments
 (0)