feat: add report.no_time config option for automatic modes

Add YAML section `report.no_time` that controls `--no-time` behavior
in automatic modes (`--commit`, `--send`). CLI flag `--no-time`
always wins. Manual `--output` ignores the YAML setting.

- Config.get_report_no_time() reads the YAML value (defaults to false)
- cli._resolve_no_time() encapsulates CLI > YAML priority
- --init-config now generates the report section
- docs updated in README.md and docs/CONFIG.md

Closes #49
This commit is contained in:
Кокос Артем Николаевич
2026-07-10 14:38:07 +07:00
parent 5e1c366a60
commit 863ad50cc3
6 changed files with 377 additions and 4 deletions

View File

@@ -72,6 +72,9 @@ def _run_init_config(config_path: str, force: bool) -> int:
"filename": "{author}_{from}_{to}.{ext}",
"default_format": "xlsx",
},
"report": {
"no_time": False,
},
"email": {
"smtp": {
"host": "",
@@ -127,6 +130,21 @@ def _compute_dedup_cutoff() -> Optional[datetime]:
return None
def _resolve_no_time(cli_flag: bool, is_auto_mode: bool) -> bool:
"""Возвращает финальное значение no_time.
Приоритет:
1. CLI-флаг --no-time (всегда побеждает).
2. YAML report.no_time (только в автоматических режимах --commit/--send).
3. Иначе False.
"""
if cli_flag:
return True
if is_auto_mode:
return Config.get_report_no_time()
return False
def _save_and_maybe_send(
rows,
output_arg: str,
@@ -378,9 +396,12 @@ def main(argv: Optional[List[str]] = None) -> int:
print(f"✅ Total issues: {len(issue_hours)} [{date_arg}]", file=sys.stderr)
is_auto_mode = args.commit or args.send
no_time = _resolve_no_time(args.no_time, is_auto_mode)
rows = build_grouped_report(
issue_hours,
fill_time=not args.no_time,
fill_time=not no_time,
by_activity=args.by_activity,
)
@@ -434,7 +455,7 @@ def main(argv: Optional[List[str]] = None) -> int:
author=Config.get_author(args.author),
from_date=from_date,
to_date=to_date,
no_time=args.no_time,
no_time=no_time,
do_send=args.send,
)
if ret != 0:
@@ -465,7 +486,7 @@ def main(argv: Optional[List[str]] = None) -> int:
author=Config.get_author(args.author),
from_date=from_date,
to_date=to_date,
no_time=args.no_time,
no_time=no_time,
do_send=True,
)
if ret != 0:

View File

@@ -61,6 +61,7 @@ class AppConfig:
output_dir: str = ""
output_filename: str = "{author}_{from}_{to}.{ext}"
output_default_format: str = "xlsx"
report_no_time: bool = False
email: EmailConfig = field(default_factory=EmailConfig)
@classmethod
@@ -86,6 +87,7 @@ class AppConfig:
"redmine",
"period",
"output",
"report",
"email",
}
for key in raw:
@@ -108,6 +110,7 @@ class AppConfig:
or "{author}_{from}_{to}.{ext}",
output_default_format=cls._resolve_str(raw, "output", "default_format")
or "xlsx",
report_no_time=cls._resolve_bool(raw, "report", "no_time"),
email=cls._resolve_email(raw),
)
@@ -344,6 +347,13 @@ class Config:
return cls._app.output_default_format or "xlsx"
return "xlsx"
@classmethod
def get_report_no_time(cls) -> bool:
"""Возвращает report.no_time из YAML-конфига (по умолчанию False)."""
if cls._app:
return cls._app.report_no_time
return False
@classmethod
def get_email_config(cls) -> "EmailConfig | None":
"""Возвращает EmailConfig из YAML-конфига или None, если не настроен."""