Add Markdown format

Closes #6
This commit is contained in:
Кокос Артем Николаевич
2026-01-22 16:52:18 +07:00
parent 2a39de467f
commit 245ea0a3fa
4 changed files with 45 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ from .client import fetch_issues_with_spent_time
from .formatter import format_compact, format_table
from .formatter_odt import format_odt
from .formatter_csv import format_csv
from .formatter_md import format_md
def parse_date_range(date_arg: str) -> tuple[str, str]:
@@ -76,8 +77,8 @@ def main(argv: Optional[List[str]] = None) -> int:
print(f"✅ Total issues: {len(issue_hours)} [{args.date}]")
if args.output:
if not (args.output.endswith(".odt") or args.output.endswith(".csv")):
print("❌ Output file must end with .odt or .csv", file=sys.stderr)
if not (args.output.endswith(".odt") or args.output.endswith(".csv") or args.output.endswith(".md")):
print("❌ Output file must end with .odt, .csv or .md", file=sys.stderr)
return 1
try:
@@ -94,6 +95,10 @@ def main(argv: Optional[List[str]] = None) -> int:
csv_content = format_csv(issue_hours, fill_time=not args.no_time)
with open(args.output, "w", encoding="utf-8", newline="") as f:
f.write(csv_content)
elif args.output.endswith(".md"):
md_content = format_md(issue_hours, fill_time=not args.no_time)
with open(args.output, "w", encoding="utf-8") as f:
f.write(md_content)
print(f"✅ Report saved to {args.output}")
except ImportError as e:
@@ -103,7 +108,7 @@ def main(argv: Optional[List[str]] = None) -> int:
print(f"❌ Import error: {e}", file=sys.stderr)
return 1
except Exception as e:
fmt = "ODT" if args.output.endswith(".odt") else "CSV"
fmt = "ODT" if args.output.endswith(".odt") else ("CSV" if args.output.endswith(".csv") else "Markdown")
print(f"{fmt} export error: {e}", file=sys.stderr)
return 1
else: