10
10
import typer
11
11
from rich .syntax import Syntax
12
12
13
+ from ... import __version__
13
14
from ..models import monkey_patch_oneof_index
14
15
from . import DEFAULT_LINE_LENGTH , VERBOSE , utils
15
16
from .runner import compile_protobufs
@@ -25,6 +26,11 @@ def callback(ctx: typer.Context) -> None:
25
26
rich .print (ctx .get_help ())
26
27
27
28
29
+ @app .command ()
30
+ def version (ctx : typer .Context ) -> None :
31
+ rich .print ("betterproto version:" , __version__ )
32
+
33
+
28
34
@app .command (context_settings = {"help_option_names" : ["-h" , "--help" ]})
29
35
@utils .run_sync
30
36
async def compile (
@@ -74,15 +80,14 @@ async def compile(
74
80
)
75
81
76
82
for error in errors :
77
- if isinstance (error , SyntaxError ):
83
+ if isinstance (error , protobuf_parser . SyntaxError ):
78
84
rich .print (
79
85
f"[red]File { str (error .file ).strip ()} :\n " ,
80
- Syntax (
81
- error .file .read_text (),
82
- "proto" ,
86
+ Syntax .from_path (
87
+ error .file ,
83
88
line_numbers = True ,
84
89
line_range = (max (error .lineno - 5 , 0 ), error .lineno ),
85
- ), # TODO switch to .from_path but it appears to be bugged and doesnt render properly
90
+ ),
86
91
f"{ ' ' * (error .offset + 3 )} ^\n SyntaxError: { error .msg } [red]" ,
87
92
file = sys .stderr ,
88
93
)
@@ -92,7 +97,7 @@ async def compile(
92
97
failed_files = "\n " .join (f" - { file } " for file in protos )
93
98
rich .print (
94
99
f"[red]Protoc failed to generate outputs for:\n \n "
95
- f"{ failed_files } \n \n See the output for the issue:\n { ' ' . join ( error . args ) } [red]" ,
100
+ f"{ failed_files } \n \n See the output for the issue:\n { error } [red]" ,
96
101
file = sys .stderr ,
97
102
)
98
103
0 commit comments