@@ -5,14 +5,20 @@ use std::time::Duration;
55
66use clap:: { Args , Parser , Subcommand , ValueEnum } ;
77use dsview_core:: {
8- resolve_capture_artifact_paths , AcquisitionSummary , AcquisitionTerminalEvent ,
9- BringUpError , CaptureArtifactPathError , CaptureCleanup , CaptureCompletion ,
10- CaptureConfigRequest , CaptureExportError , CaptureRunError , CaptureRunRequest , Discovery ,
11- NativeErrorCode , RuntimeError , SelectionHandle , SupportedDevice , describe_native_error ,
8+ describe_native_error , resolve_capture_artifact_paths , AcquisitionSummary ,
9+ AcquisitionTerminalEvent , BringUpError , CaptureArtifactPathError , CaptureCleanup ,
10+ CaptureCompletion , CaptureConfigRequest , CaptureExportError , CaptureRunError ,
11+ CaptureRunRequest , Discovery , NativeErrorCode , RuntimeError , SelectionHandle , SupportedDevice ,
1212} ;
1313use serde:: Serialize ;
1414
15+ const BUILD_VERSION : & str = match option_env ! ( "DSVIEW_BUILD_VERSION" ) {
16+ Some ( version) => version,
17+ None => env ! ( "CARGO_PKG_VERSION" ) ,
18+ } ;
19+
1520#[ derive( Parser , Debug ) ]
21+ #[ command( version = BUILD_VERSION ) ]
1622#[ command( name = "dsview-cli" ) ]
1723#[ command( about = "Scriptable DSLogic bring-up CLI" ) ]
1824struct Cli {
@@ -223,8 +229,10 @@ fn run_open(args: OpenArgs) -> Result<(), FailedCommand> {
223229}
224230
225231fn run_capture ( args : CaptureArgs ) -> Result < ( ) , FailedCommand > {
226- let artifact_paths = resolve_capture_artifact_paths ( & args. output , args. metadata_output . as_ref ( ) )
227- . map_err ( |error| command_error ( args. runtime . format , classify_artifact_path_error ( & error) ) ) ?;
232+ let artifact_paths =
233+ resolve_capture_artifact_paths ( & args. output , args. metadata_output . as_ref ( ) ) . map_err (
234+ |error| command_error ( args. runtime . format , classify_artifact_path_error ( & error) ) ,
235+ ) ?;
228236 let discovery = connect_runtime ( & args. runtime ) ?;
229237 let handle = SelectionHandle :: new ( args. handle )
230238 . ok_or_else ( || command_error ( args. runtime . format , invalid_handle_error ( ) ) ) ?;
@@ -239,12 +247,14 @@ fn run_capture(args: CaptureArgs) -> Result<(), FailedCommand> {
239247 wait_timeout : Duration :: from_millis ( args. wait_timeout_ms ) ,
240248 poll_interval : Duration :: from_millis ( args. poll_interval_ms ) ,
241249 } ;
242- let validated_config = discovery. validate_capture_config ( & run_request. config ) . map_err ( |error| {
243- command_error (
244- args. runtime . format ,
245- classify_runtime_error ( & RuntimeError :: InvalidArgument ( error. to_string ( ) ) ) ,
246- )
247- } ) ?;
250+ let validated_config = discovery
251+ . validate_capture_config ( & run_request. config )
252+ . map_err ( |error| {
253+ command_error (
254+ args. runtime . format ,
255+ classify_runtime_error ( & RuntimeError :: InvalidArgument ( error. to_string ( ) ) ) ,
256+ )
257+ } ) ?;
248258 let result = discovery
249259 . run_capture ( & run_request)
250260 . map_err ( |error| command_error ( args. runtime . format , classify_capture_error ( & error) ) ) ?;
@@ -255,7 +265,7 @@ fn run_capture(args: CaptureArgs) -> Result<(), FailedCommand> {
255265 vcd_path : artifact_paths. vcd_path ,
256266 metadata_path : Some ( artifact_paths. metadata_path ) ,
257267 tool_name : env ! ( "CARGO_PKG_NAME" ) . to_string ( ) ,
258- tool_version : env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ,
268+ tool_version : BUILD_VERSION . to_string ( ) ,
259269 capture_started_at : std:: time:: SystemTime :: now ( ) ,
260270 device_model : "DSLogic Plus" . to_string ( ) ,
261271 device_stable_id : "dslogic-plus" . to_string ( ) ,
@@ -297,7 +307,10 @@ fn classify_artifact_path_error(error: &CaptureArtifactPathError) -> ErrorRespon
297307 match error {
298308 CaptureArtifactPathError :: InvalidVcdExtension { path } => ErrorResponse {
299309 code : "capture_output_path_invalid" ,
300- message : format ! ( "VCD output path `{}` must use the .vcd extension" , path. display( ) ) ,
310+ message : format ! (
311+ "VCD output path `{}` must use the .vcd extension" ,
312+ path. display( )
313+ ) ,
301314 detail : None ,
302315 native_error : None ,
303316 terminal_event : None ,
@@ -726,9 +739,7 @@ pub(crate) fn capture_success_text(
726739 vcd_path : & str ,
727740 metadata_path : & str ,
728741) -> String {
729- format ! (
730- "capture {completion}\n vcd {vcd_path}\n metadata {metadata_path}"
731- )
742+ format ! ( "capture {completion}\n vcd {vcd_path}\n metadata {metadata_path}" )
732743}
733744
734745fn render_error ( format : OutputFormat , error : & ErrorResponse ) {
@@ -997,7 +1008,10 @@ mod tests {
9971008 completion_name( CaptureCompletion :: CleanSuccess ) ,
9981009 "clean_success"
9991010 ) ;
1000- assert_eq ! ( completion_name( CaptureCompletion :: RunFailure ) , "run_failure" ) ;
1011+ assert_eq ! (
1012+ completion_name( CaptureCompletion :: RunFailure ) ,
1013+ "run_failure"
1014+ ) ;
10011015 assert_eq ! ( completion_name( CaptureCompletion :: Detached ) , "detach" ) ;
10021016 assert_eq ! ( completion_name( CaptureCompletion :: Timeout ) , "timeout" ) ;
10031017 }
0 commit comments