Skip to content

Commit 4943d11

Browse files
committed
feat: --yesterday flag
1 parent 6d2f514 commit 4943d11

File tree

3 files changed

+58
-15
lines changed

3 files changed

+58
-15
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ lightman run --dry-run --agent openai --score 9
240240
| `--prompt-file` | File containing prompt templates | `lightman.toml` |
241241
| `--start-date` | Start date to retrieve articles | None |
242242
| `--today` | Retrieve articles from today | None |
243+
| `--yesterday` | Retrieve articles from yesterday | None |
243244

244245
### Example Workflows
245246

src/lightman_ai/cli.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from datetime import date, datetime, time
2+
from datetime import date, datetime, time, timedelta
33
from importlib import metadata
44
from zoneinfo import ZoneInfo
55

@@ -70,6 +70,7 @@ def entry_point() -> None:
7070
)
7171
@click.option("--start-date", type=click.DateTime(formats=["%Y-%m-%d"]), help="Start date to retrieve articles")
7272
@click.option("--today", is_flag=True, help="Retrieve articles from today.")
73+
@click.option("--yesterday", is_flag=True, help="Retrieve articles from yesterday.")
7374
def run(
7475
agent: str,
7576
prompt: str,
@@ -82,6 +83,7 @@ def run(
8283
dry_run: bool,
8384
start_date: date | None,
8485
today: bool,
86+
yesterday: bool,
8587
) -> int:
8688
"""
8789
Entrypoint of the application.
@@ -91,11 +93,15 @@ def run(
9193
load_dotenv(env_file)
9294
configure_sentry()
9395

94-
if start_date and today:
95-
raise click.UsageError("--today and --start-date cannot be set at the same time.")
96+
mutually_exclusive_fields_set = [x for x in [start_date, today, yesterday] if x]
97+
if len(mutually_exclusive_fields_set) > 1:
98+
raise click.UsageError("--today, --yesterday and --start-date are mutually exclusive. Set one at a time.")
9699
elif today:
97100
now = datetime.now(ZoneInfo(settings.TIME_ZONE))
98101
start_datetime = datetime.combine(now, time(0, 0), tzinfo=ZoneInfo(settings.TIME_ZONE))
102+
elif yesterday:
103+
yesterday_date = datetime.now(ZoneInfo(settings.TIME_ZONE)) - timedelta(days=1)
104+
start_datetime = datetime.combine(yesterday_date, time(0, 0), tzinfo=ZoneInfo(settings.TIME_ZONE))
99105
elif isinstance(start_date, date):
100106
start_datetime = datetime.combine(start_date, time(0, 0), tzinfo=ZoneInfo(settings.TIME_ZONE))
101107
else:

tests/test_cli.py

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def test_arguments(self, m_prompt: Mock, m_config: Mock, m_lightman: Mock, m_loa
6363
@patch("lightman_ai.cli.PromptConfig.get_config_from_file")
6464
def test_start_date(self, m_prompt: Mock, m_config: Mock, m_lightman: Mock, m_load_dotenv: Mock) -> None:
6565
runner = CliRunner()
66-
m_prompt.return_value = PromptConfig({"eval": "eval prompt"})
6766
m_config.return_value = FileConfig()
6867

6968
with patch_config_file():
@@ -89,19 +88,56 @@ def test_start_date(self, m_prompt: Mock, m_config: Mock, m_lightman: Mock, m_lo
8988
assert result.exit_code == 0
9089
assert m_lightman.call_count == 1
9190
assert m_lightman.call_args == call(
92-
agent="gemini",
93-
prompt="eval prompt",
94-
score_threshold=1,
95-
dry_run=False,
96-
project_key=None,
97-
request_id_type=None,
98-
model=None,
91+
agent=ANY,
92+
prompt=ANY,
93+
score_threshold=ANY,
94+
dry_run=ANY,
95+
project_key=ANY,
96+
request_id_type=ANY,
97+
model=ANY,
9998
start_date=datetime(2025, 7, 29, 0, 0, tzinfo=ZoneInfo(key="UTC")),
10099
)
101-
assert m_config.call_count == 1
102-
assert m_config.call_args == call(config_section="my-config", path="config-path")
103-
assert m_prompt.call_args == call(path="prompt file")
104-
assert m_load_dotenv.call_args == call(".env") # Default env file
100+
101+
@patch("lightman_ai.cli.load_dotenv")
102+
@patch("lightman_ai.cli.lightman")
103+
@patch("lightman_ai.cli.FileConfig.get_config_from_file")
104+
@patch("lightman_ai.cli.PromptConfig.get_config_from_file")
105+
@freeze_time("2025-07-29 19:00:00")
106+
def test_yesterday(self, m_prompt: Mock, m_config: Mock, m_lightman: Mock, m_load_dotenv: Mock) -> None:
107+
runner = CliRunner()
108+
m_config.return_value = FileConfig()
109+
110+
with patch_config_file():
111+
result = runner.invoke(
112+
cli.run,
113+
[
114+
"--agent",
115+
"gemini",
116+
"--prompt",
117+
"eval",
118+
"--prompt-file",
119+
"prompt file",
120+
"--score",
121+
"1",
122+
"--config-file",
123+
"config-path",
124+
"--config",
125+
"my-config",
126+
"--yesterday",
127+
],
128+
)
129+
assert result.exit_code == 0
130+
assert m_lightman.call_count == 1
131+
assert m_lightman.call_args == call(
132+
agent=ANY,
133+
prompt=ANY,
134+
score_threshold=ANY,
135+
dry_run=ANY,
136+
project_key=ANY,
137+
request_id_type=ANY,
138+
model=ANY,
139+
start_date=datetime(2025, 7, 28, 0, 0, tzinfo=ZoneInfo(key="UTC")),
140+
)
105141

106142
@patch("lightman_ai.cli.load_dotenv")
107143
@patch("lightman_ai.cli.lightman")

0 commit comments

Comments
 (0)