diff --git a/midas/cli/commands/check.py b/midas/cli/commands/check.py index f59c479..22f654e 100644 --- a/midas/cli/commands/check.py +++ b/midas/cli/commands/check.py @@ -14,7 +14,7 @@ from midas.cli.highlighter import DiagnosticsHighlighter from midas.cli.utils import DiagnosticPrinter -@click.command() +@click.command(help="Run type checker and report diagnostics") @click.argument("file", type=click.File("r")) @click.option("-t", "--types", type=click.File("r"), multiple=True) @click.option("-l", "--highlight", type=click.File("w")) diff --git a/midas/cli/commands/compile.py b/midas/cli/commands/compile.py index 7d495fc..5a410f7 100644 --- a/midas/cli/commands/compile.py +++ b/midas/cli/commands/compile.py @@ -3,19 +3,20 @@ # midas compile [--types ] [-o ] [--assertions|--strict|--no-checks] # ``` +import sys from pathlib import Path from typing import TextIO import click from midas.checker.checker import TypeChecker -from midas.checker.diagnostic import Diagnostic +from midas.checker.diagnostic import Diagnostic, DiagnosticType from midas.cli.utils import DiagnosticPrinter from midas.generator.generator import Generator from midas.utils import TypedAST -@click.command() +@click.command(help="Compile source") @click.argument("file", type=click.File("r")) @click.option("-t", "--types", type=click.File("r"), multiple=True) def compile( @@ -34,5 +35,8 @@ def compile( printer = DiagnosticPrinter() printer.print_all(diagnostics) + if any(map(lambda d: d.type == DiagnosticType.ERROR, diagnostics)): + sys.exit(1) + generator = Generator(workdir=source_path.parent) generator.generate(typed_ast, source_path) diff --git a/midas/cli/commands/format.py b/midas/cli/commands/format.py index ce570c0..1bd3dbf 100644 --- a/midas/cli/commands/format.py +++ b/midas/cli/commands/format.py @@ -9,7 +9,7 @@ from midas.lexer.token import Token from midas.parser.midas import MidasParser -@click.command() +@click.command(help="Parse and pretty print a Midas file") @click.argument("file", type=click.File("r")) @click.option("-o", "--output", type=click.File("w"), default="-") def format(file: TextIO, output: TextIO): diff --git a/midas/cli/commands/highlight.py b/midas/cli/commands/highlight.py index acb05e9..cf04a8d 100644 --- a/midas/cli/commands/highlight.py +++ b/midas/cli/commands/highlight.py @@ -46,7 +46,10 @@ def highlight_midas(source: str, path: str) -> Highlighter: return highlighter -@click.command() +@click.command( + help="Parse a Python or Midas file and produce a highlighted version showing AST node types inline", + short_help="Parse and highlight a Python or Midas file", +) @click.argument("file", type=click.File("r")) @click.option("-o", "--output", type=click.File("w"), default="-") def highlight(output: TextIO, file: TextIO): diff --git a/midas/cli/commands/parse.py b/midas/cli/commands/parse.py index c2a2f1a..d2f5338 100644 --- a/midas/cli/commands/parse.py +++ b/midas/cli/commands/parse.py @@ -45,7 +45,7 @@ def dump_midas_ast(source: str, filename: str) -> str: return dump -@click.command() +@click.command(help="Parse a Python or Midas file and pretty-print its AST") @click.argument("file", type=click.File("r")) @click.option("--raw", is_flag=True) def parse(file: TextIO, raw: bool): diff --git a/midas/cli/commands/registry.py b/midas/cli/commands/registry.py index 502be75..4e830be 100644 --- a/midas/cli/commands/registry.py +++ b/midas/cli/commands/registry.py @@ -12,7 +12,7 @@ from midas.checker.checker import TypeChecker from midas.checker.types import Type -@click.command() +@click.command(help="Dump types registry") @click.option("-t", "--types", type=click.File("r"), multiple=True) def dump_registry( types: tuple[TextIO], diff --git a/midas/cli/commands/types.py b/midas/cli/commands/types.py index 439611d..d17a0a8 100644 --- a/midas/cli/commands/types.py +++ b/midas/cli/commands/types.py @@ -14,7 +14,7 @@ from midas.cli.highlighter import DiagnosticsHighlighter from midas.cli.utils import DiagnosticPrinter -@click.command() +@click.command(help="Print typing judgements") @click.argument("file", type=click.File("r")) @click.option("-t", "--types", type=click.File("r"), multiple=True) @click.option("-l", "--highlight", type=click.File("w")) diff --git a/midas/cli/commands/validate.py b/midas/cli/commands/validate.py index 44e33bb..931c3e5 100644 --- a/midas/cli/commands/validate.py +++ b/midas/cli/commands/validate.py @@ -14,7 +14,7 @@ from midas.cli.highlighter import DiagnosticsHighlighter from midas.cli.utils import DiagnosticPrinter -@click.command() +@click.command(help="Validate Midas definitions") @click.argument("file", type=click.File("r")) @click.option("-l", "--highlight", type=click.File("w")) def validate(