feat: --commit flag (#44)
- --commit: после генерации отчёта сохраняет период в period.last_used.from/to YAML-конфига - При period.dynamic=true следующий запуск вычисляет период от last_used: полный месяц → следующий месяц, произвольный диапазон → та же длина - При period.dynamic=false перезаписывает default_from/default_to - При period.precision=datetime сохраняет timestamps с точностью до секунд - --commit без --output сохраняет отчёт по шаблону из конфига - compute_next_period() в config.py - save_period_to_config() в yaml_config.py - 23 новых теста (7 CLI, 6 config, 6 yaml, 4 date_range) Closes #44
This commit is contained in:
@@ -149,3 +149,38 @@ def resolve_output_path(
|
||||
arg = f"{arg}.{default_format}"
|
||||
|
||||
return arg
|
||||
|
||||
|
||||
def save_period_to_config(
|
||||
config_path: str,
|
||||
from_str: str,
|
||||
to_str: str,
|
||||
precision: str,
|
||||
dynamic: bool,
|
||||
) -> None:
|
||||
"""Save committed period to YAML config file.
|
||||
|
||||
Writes period.last_used.from / period.last_used.to.
|
||||
When dynamic=False, also overwrites period.default_from / period.default_to.
|
||||
|
||||
Preserves all other sections unchanged. Creates config file if missing.
|
||||
"""
|
||||
import yaml
|
||||
|
||||
path = Path(config_path)
|
||||
raw: dict = {}
|
||||
if path.exists():
|
||||
with open(path, "r", encoding="utf-8") as fh:
|
||||
raw = yaml.safe_load(fh) or {}
|
||||
|
||||
period = raw.setdefault("period", {})
|
||||
period["last_used"] = {"from": from_str, "to": to_str}
|
||||
|
||||
if not dynamic:
|
||||
period["default_from"] = from_str.split("T")[0] if "T" in from_str else from_str
|
||||
period["default_to"] = to_str.split("T")[0] if "T" in to_str else to_str
|
||||
|
||||
ensure_config_dir(path.parent)
|
||||
with open(path, "w", encoding="utf-8") as fh:
|
||||
yaml.dump(raw, fh, allow_unicode=True, default_flow_style=False, sort_keys=False)
|
||||
path.chmod(0o600)
|
||||
|
||||
Reference in New Issue
Block a user