• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Hylbert / Mark2TeX / 25639311457

10 May 2026 08:43PM UTC coverage: 63.177% (+0.7%) from 62.516%
25639311457

push

github

web-flow
Merge pull request #54 from Hylbert/feat/new-templates-dissertacao-relatorio-acm

feat: add new templates (dissertacao, relatorio, acm) and fix notas-aula compilation errors

59 of 83 new or added lines in 3 files covered. (71.08%)

1050 of 1662 relevant lines covered (63.18%)

0.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.93
/mark2tex/cli.py
1
"""Mark2TeX CLI entry-point."""
2
from __future__ import annotations
1✔
3

4
import argparse
1✔
5
import sys
1✔
6

7
from .docker_manager import DockerManager, clean_cache, uninstall_docker_assets
1✔
8
from .main import main as run_app
1✔
9
from .setup_env import ensure_environment
1✔
10
from .template_meta import load_template_meta
1✔
11
from .yaml_injector import has_backup, restore_file
1✔
12

13

14
def build_parser() -> argparse.ArgumentParser:
1✔
15
    parser = argparse.ArgumentParser(
1✔
16
        prog="mark2tex",
17
        description="Convert Markdown to professional PDF via LaTeX templates.",
18
    )
19
    subparsers = parser.add_subparsers(dest="command")
1✔
20

21
    subparsers.add_parser("tui",       help="Open the TUI dashboard (default)")
1✔
22
    subparsers.add_parser("check",     help="Run a full system health check")
1✔
23
    subparsers.add_parser("doctor",    help="Alias for 'check' (deprecated)")
1✔
24
    subparsers.add_parser("uninstall", help="Remove Mark2TeX Docker assets")
1✔
25

26
    init_cmd = subparsers.add_parser(
1✔
27
        "init",
28
        help="Copy a template + example file into the current directory",
29
    )
30
    init_cmd.add_argument(
1✔
31
        "--template",
32
        metavar="NAME",
33
        default=None,
34
        help="Template name to copy (e.g. artigo-ieee, tcc-abnt, doc-tecnica)",
35
    )
36

37
    restore_cmd = subparsers.add_parser(
1✔
38
        "restore",
39
        help="Restore a .md file to its state before YAML frontmatter was injected",
40
    )
41
    restore_cmd.add_argument(
1✔
42
        "file",
43
        metavar="FILE",
44
        help="Path to the .md file to restore",
45
    )
46

47
    clean_cmd = subparsers.add_parser(
1✔
48
        "clean",
49
        help=(
50
            "Remove latexmk build cache. "
51
            "Without FILE, wipes the entire cache for all documents. "
52
            "With FILE, removes only the cache for that document."
53
        ),
54
    )
55
    clean_cmd.add_argument(
1✔
56
        "file",
57
        metavar="FILE",
58
        nargs="?",
59
        default=None,
60
        help="Path to the .md file whose cache should be removed (optional)",
61
    )
62

63
    template_cmd = subparsers.add_parser(
1✔
64
        "template",
65
        help="Inspect available templates",
66
    )
67
    template_cmd.add_argument(
1✔
68
        "action",
69
        choices=["list"],
70
        help="Action to perform (currently only 'list')",
71
    )
72
    template_cmd.add_argument(
1✔
73
        "--verbose",
74
        action="store_true",
75
        help="Show detailed information for each template",
76
    )
77

78
    return parser
1✔
79

80

81
def _run_check() -> None:
1✔
82
    """Execute all system probes and render a Rich report."""
83
    from rich.console import Console
×
84

85
    from . import config as cfg
×
86
    from .check_renderer import render_check_results
×
87
    from .checker import run_all_checks
×
88

89
    lang    = cfg.load().get("language", "pt_BR")
×
90
    results = run_all_checks()
×
91
    code    = render_check_results(results, lang=lang, console=Console())
×
92
    sys.exit(code)
×
93

94

95
def _run_clean(file: str | None) -> None:
1✔
96
    """Remove latexmk cache and print a status message."""
97
    from .i18n import t
×
98

99
    ok, path = clean_cache(file)
×
100
    if ok:
×
101
        print(t("clean.removed").format(path=path))
×
102
    else:
103
        print(t("clean.error").format(path=path), file=sys.stderr)
×
104
        sys.exit(1)
×
105

106

107
def _run_template_list(verbose: bool) -> None:
1✔
108
    """Print available templates, optionally enriched with metadata."""
109
    mgr = DockerManager()
1✔
110
    slugs = mgr.list_templates()
1✔
111
    meta = load_template_meta(mgr.templates_dir)
1✔
112

113
    if not verbose:
1✔
114
        for slug in slugs:
1✔
115
            print(slug)
1✔
116
        return
1✔
117

NEW
118
    for slug in slugs:
×
NEW
119
        info = meta.get(slug)
×
NEW
120
        if not info:
×
NEW
121
            print(slug)
×
NEW
122
            continue
×
NEW
123
        line = f"{info.slug}: {info.name}"
×
NEW
124
        details: list[str] = []
×
NEW
125
        if info.norm:
×
NEW
126
            details.append(info.norm)
×
NEW
127
        if info.document_type:
×
NEW
128
            details.append(info.document_type)
×
NEW
129
        if info.level:
×
NEW
130
            details.append(info.level)
×
NEW
131
        if info.language:
×
NEW
132
            details.append(info.language)
×
NEW
133
        if details:
×
NEW
134
            line += " [" + ", ".join(details) + "]"
×
NEW
135
        if info.description:
×
NEW
136
            line += f"\n  {info.description}"
×
NEW
137
        print(line)
×
138

139

140
def main() -> None:
1✔
141
    parser  = build_parser()
1✔
142
    args    = parser.parse_args()
1✔
143
    command = args.command or "tui"
1✔
144

145
    if command == "check":
1✔
146
        _run_check()
×
147
        return
×
148

149
    if command == "doctor":
1✔
150
        from rich.console import Console
1✔
151
        Console().print(
1✔
152
            "[#e0a24a]⚠️  `mark2tex doctor` is deprecated — use `mark2tex check` instead.[/]"
153
        )
154
        _run_check()
1✔
155
        return
1✔
156

157
    if command == "uninstall":
1✔
158
        uninstall_docker_assets()
1✔
159
        print("Run `pipx uninstall mark2tex` to remove the package as well.")
1✔
160
        return
1✔
161

162
    if command == "init":
1✔
163
        from .onboarding import run_init
×
164
        run_init(template=getattr(args, "template", None))
×
165
        return
×
166

167
    if command == "restore":
1✔
168
        file = args.file
×
169
        if not has_backup(file):
×
170
            print(f"✗ No backup found for '{file}'. Nothing to restore.", file=sys.stderr)
×
171
            sys.exit(1)
×
172
        success, msg = restore_file(file)
×
173
        if success:
×
174
            print(f"✔ {msg}")
×
175
        else:
176
            print(f"✗ {msg}", file=sys.stderr)
×
177
            sys.exit(1)
×
178
        return
×
179

180
    if command == "clean":
1✔
181
        _run_clean(getattr(args, "file", None))
×
182
        return
×
183

184
    if command == "template":
1✔
185
        _run_template_list(bool(getattr(args, "verbose", False)))
1✔
186
        return
1✔
187

188
    # Default: open TUI (with first-run onboarding if needed)
189
    ensure_environment()
×
190
    run_app()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc