11use std:: {
2- io:: { self , IsTerminal } ,
3- path:: PathBuf ,
4- sync:: { Arc , Mutex } ,
2+ io:: { self , IsTerminal } , path:: PathBuf , process:: ExitCode , sync:: { Arc , Mutex }
53} ;
64
5+ use ariadne:: ReportKind ;
6+
77use crate :: {
88 ast:: { Diagnostic , FileId , Files , SourceFilePath , Span , StoredFile } ,
99 driver:: { SmtVcCheckResult , SourceUnitName } ,
@@ -17,13 +17,15 @@ use super::{unless_fatal_error, Server, ServerError};
1717pub struct CliServer {
1818 werr : bool ,
1919 files : Arc < Mutex < Files > > ,
20+ has_emitted_errors : bool ,
2021}
2122
2223impl CliServer {
2324 pub fn new ( input_options : & InputOptions ) -> Self {
2425 CliServer {
2526 werr : input_options. werr ,
2627 files : Default :: default ( ) ,
28+ has_emitted_errors : false ,
2729 }
2830 }
2931
@@ -62,6 +64,8 @@ impl Server for CliServer {
6264 }
6365
6466 fn add_diagnostic ( & mut self , diagnostic : Diagnostic ) -> Result < ( ) , VerifyError > {
67+ self . has_emitted_errors =
68+ self . has_emitted_errors || self . werr || diagnostic. kind ( ) == ReportKind :: Error ;
6569 let files = self . files . lock ( ) . unwrap ( ) ;
6670 print_diagnostic ( & files, diagnostic) ?;
6771 Ok ( ( ) )
@@ -97,6 +101,14 @@ impl Server for CliServer {
97101 // Not relevant for CLI
98102 Ok ( ( ) )
99103 }
104+
105+ fn exit_code ( & self ) -> ExitCode {
106+ if self . has_emitted_errors {
107+ ExitCode :: FAILURE
108+ } else {
109+ ExitCode :: SUCCESS
110+ }
111+ }
100112}
101113
102114fn print_diagnostic ( mut files : & Files , diagnostic : Diagnostic ) -> io:: Result < ( ) > {
0 commit comments