File tree Expand file tree Collapse file tree 8 files changed +97
-23
lines changed
Expand file tree Collapse file tree 8 files changed +97
-23
lines changed Original file line number Diff line number Diff line change @@ -11,15 +11,17 @@ version = "0.4.0"
1111edition = " 2024"
1212
1313[workspace .dependencies ]
14+ cairo-lang-sierra = " 2.10.1"
15+ cairo-lang-sierra-to-casm = " 2.10.1"
16+ cairo-lang-starknet-classes = " 2.10.1"
17+ cairo-annotations = " 0.2.2"
18+
1419anyhow = " 1.0.96"
1520assert_fs = " 1.1.2"
1621camino = " 1.1.9"
1722clap = { version = " 4.5.30" , features = [" derive" ] }
1823criterion = " 0.5"
19- cairo-annotations = " 0.2.2"
20- cairo-lang-sierra = " 2.10.1"
21- cairo-lang-sierra-to-casm = " 2.10.1"
22- cairo-lang-starknet-classes = " 2.10.1"
24+ console = " 0.15.10"
2325itertools = " 0.14.0"
2426ignore = " 0.4.23"
2527serde = " 1.0.218"
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ edition.workspace = true
55
66[dependencies ]
77cairo-coverage-core = { path = " ../cairo-coverage-core" }
8+ console.workspace = true
89camino.workspace = true
910anyhow.workspace = true
1011clap.workspace = true
Original file line number Diff line number Diff line change @@ -34,11 +34,11 @@ pub enum IncludedComponent {
3434fn parse_trace_file ( path : & str ) -> Result < Utf8PathBuf > {
3535 let trace_file = Utf8PathBuf :: from ( path) ;
3636
37- ensure ! ( trace_file. exists( ) , "Trace file does not exist" ) ;
38- ensure ! ( trace_file. is_file( ) , "Trace file is not a file" ) ;
37+ ensure ! ( trace_file. exists( ) , "trace file does not exist" ) ;
38+ ensure ! ( trace_file. is_file( ) , "trace file is not a file" ) ;
3939 ensure ! (
4040 matches!( trace_file. extension( ) , Some ( "json" ) ) ,
41- "Trace file must have a JSON extension"
41+ "trace file must have a JSON extension"
4242 ) ;
4343
4444 Ok ( trace_file)
@@ -47,8 +47,8 @@ fn parse_trace_file(path: &str) -> Result<Utf8PathBuf> {
4747fn parse_project_path ( path : & str ) -> Result < Utf8PathBuf > {
4848 let project_path = Utf8PathBuf :: from ( path) ;
4949
50- ensure ! ( project_path. exists( ) , "Project path does not exist" ) ;
51- ensure ! ( project_path. is_dir( ) , "Project path is not a directory" ) ;
50+ ensure ! ( project_path. exists( ) , "project path does not exist" ) ;
51+ ensure ! ( project_path. is_dir( ) , "project path is not a directory" ) ;
5252
5353 Ok ( project_path)
5454}
Original file line number Diff line number Diff line change 11use crate :: args:: clean:: CleanArgs ;
2+ use crate :: ui;
23use anyhow:: { Context , Result } ;
34use std:: fs;
45use walkdir:: WalkDir ;
@@ -13,7 +14,7 @@ pub fn run(
1314) -> Result < ( ) > {
1415 let target_file_name = files_to_delete
1516 . file_name ( )
16- . context ( "Failed to obtain the file name from `files_to_delete`. " ) ?;
17+ . context ( "failed to obtain the file name from `--files-to-delete` " ) ?;
1718
1819 WalkDir :: new ( root_dir)
1920 . into_iter ( )
@@ -24,16 +25,17 @@ pub fn run(
2425
2526 if let Some ( file_name) = path. file_name ( ) {
2627 if file_name == target_file_name {
27- println ! ( "Deleting file: {}" , path. display( ) ) ;
28+ let path_display = path. display ( ) ;
29+ ui:: msg ( format ! ( "deleting file: {path_display}" ) ) ;
2830 fs:: remove_file ( path)
29- . with_context ( || format ! ( "Failed to delete file: {}" , path . display ( ) ) ) ?;
31+ . with_context ( || format ! ( "failed to delete file: {path_display}" ) ) ?;
3032 }
3133 }
3234
3335 Ok ( ( ) )
3436 } ) ?;
3537
36- println ! ( "Cleanup complete. ") ;
38+ ui :: msg ( "cleanup complete") ;
3739 Ok ( ( ) )
3840}
3941
Original file line number Diff line number Diff line change @@ -25,9 +25,9 @@ pub fn run(
2525 . append ( true )
2626 . create ( true )
2727 . open ( & output_path)
28- . context ( format ! ( "Failed to open output file at path: {output_path}" ) ) ?
28+ . context ( format ! ( "failed to open output file at path: {output_path}" ) ) ?
2929 . write_all ( lcov. as_bytes ( ) )
30- . context ( "Failed to write to output file" ) ?;
30+ . context ( "failed to write to output file" ) ?;
3131
3232 Ok ( ( ) )
3333}
Original file line number Diff line number Diff line change 11use crate :: args:: { CairoCoverageArgs , Command } ;
22use anyhow:: Result ;
3+
34use clap:: Parser ;
5+ use std:: process:: ExitCode ;
46
57mod args;
68mod commands;
9+ mod ui;
10+
11+ fn main ( ) -> ExitCode {
12+ if let Err ( error) = main_inner ( ) {
13+ ui:: error ( error) ;
14+ ExitCode :: FAILURE
15+ } else {
16+ ExitCode :: SUCCESS
17+ }
18+ }
719
8- fn main ( ) -> Result < ( ) > {
20+ fn main_inner ( ) -> Result < ( ) > {
921 let cairo_coverage_args = CairoCoverageArgs :: parse ( ) ;
1022
11- let command = match cairo_coverage_args. command {
12- Some ( command) => command,
13- // TODO:
14- // * In 0.5.0 add deprecation warning
15- // * In 0.6.0 remove the default command
16- None => Command :: Run ( cairo_coverage_args. run_args . unwrap_or_else ( || {
23+ // TODO:
24+ // * In 0.6.0 remove the default command
25+ let command = if let Some ( command) = cairo_coverage_args. command {
26+ command
27+ } else {
28+ ui:: warning ( "running `cairo-coverage` without a subcommand is deprecated" ) ;
29+ ui:: help ( "consider using `cairo-coverage run`" ) ;
30+
31+ Command :: Run ( cairo_coverage_args. run_args . unwrap_or_else ( || {
1732 unreachable ! ( "`run_args` should be set when no subcommand is provided" )
18- } ) ) ,
33+ } ) )
1934 } ;
2035
2136 commands:: run ( command)
Original file line number Diff line number Diff line change 1+ //! UI utilities for the Cairo coverage tool.
2+ //! All human-oriented messaging must use this module to communicate with the user.
3+ //! Messages should be lowercased and should not end with a period.
4+ use console:: style;
5+ use std:: fmt:: Display ;
6+
7+ /// Print a warning message.
8+ pub fn warning ( message : impl Display ) {
9+ let tag = style ( "warning" ) . yellow ( ) ;
10+ println ! ( "{tag}: {message}" ) ;
11+ }
12+
13+ /// Print an error message.
14+ pub fn error ( message : impl Display ) {
15+ let tag = style ( "error" ) . red ( ) ;
16+ println ! ( "{tag}: {message}" ) ;
17+ }
18+
19+ /// Print a help message.
20+ pub fn help ( message : impl Display ) {
21+ let tag = style ( "help" ) . bold ( ) ;
22+ println ! ( "{tag}: {message}" ) ;
23+ }
24+
25+ /// Print a message.
26+ pub fn msg ( message : impl Display ) {
27+ println ! ( "{message}" ) ;
28+ }
You can’t perform that action at this time.
0 commit comments