@@ -6,12 +6,13 @@ use std::time::{SystemTime, UNIX_EPOCH};
66
77use rsscript:: {
88 Diagnostic , analyze_source, analyze_source_with_interfaces, check_generated_rust_package,
9- core_interfaces, explain_diagnostic_code, format_diagnostic_explanation,
10- format_diagnostics_human, format_diagnostics_json, format_package_review_human,
11- format_package_review_json, format_review_human, format_review_json, format_review_map_human,
12- format_review_map_json, lint_source, lower_source_to_rust, lower_source_to_rust_package,
13- parse_runtime_diagnostics, parse_source_map_json, remap_rustc_diagnostic_json_lines,
14- review_map_sources, review_package_dir, review_sources, write_generated_rust_package,
9+ core_interfaces, diff_package_dirs, explain_diagnostic_code, format_diagnostic_explanation,
10+ format_diagnostics_human, format_diagnostics_json, format_package_diff_human,
11+ format_package_diff_json, format_package_review_human, format_package_review_json,
12+ format_review_human, format_review_json, format_review_map_human, format_review_map_json,
13+ lint_source, lower_source_to_rust, lower_source_to_rust_package, parse_runtime_diagnostics,
14+ parse_source_map_json, remap_rustc_diagnostic_json_lines, review_map_sources,
15+ review_package_dir, review_sources, write_generated_rust_package,
1516} ;
1617
1718fn main ( ) -> ExitCode {
@@ -41,6 +42,11 @@ fn main() -> ExitCode {
4142fn run_package ( args : & [ String ] ) -> ExitCode {
4243 match parse_package_args ( args) {
4344 PackageCommand :: Review { json, path } => run_package_review ( json, path) ,
45+ PackageCommand :: Diff {
46+ json,
47+ old_path,
48+ new_path,
49+ } => run_package_diff ( json, old_path, new_path) ,
4450 PackageCommand :: Invalid => {
4551 print_usage ( ) ;
4652 ExitCode :: from ( 2 )
@@ -778,7 +784,15 @@ enum ReviewCommand<'a> {
778784}
779785
780786enum PackageCommand < ' a > {
781- Review { json : bool , path : & ' a str } ,
787+ Review {
788+ json : bool ,
789+ path : & ' a str ,
790+ } ,
791+ Diff {
792+ json : bool ,
793+ old_path : & ' a str ,
794+ new_path : & ' a str ,
795+ } ,
782796 Invalid ,
783797}
784798
@@ -790,7 +804,7 @@ fn parse_package_args(args: &[String]) -> PackageCommand<'_> {
790804 for arg in args {
791805 if arg == "--json" {
792806 json = true ;
793- } else if arg == "review" {
807+ } else if arg == "review" || arg == "diff" {
794808 command = Some ( arg. as_str ( ) ) ;
795809 } else {
796810 paths. push ( arg. as_str ( ) ) ;
@@ -799,6 +813,11 @@ fn parse_package_args(args: &[String]) -> PackageCommand<'_> {
799813
800814 match ( command, paths. as_slice ( ) ) {
801815 ( Some ( "review" ) , [ path] ) => PackageCommand :: Review { json, path } ,
816+ ( Some ( "diff" ) , [ old_path, new_path] ) => PackageCommand :: Diff {
817+ json,
818+ old_path,
819+ new_path,
820+ } ,
802821 _ => PackageCommand :: Invalid ,
803822 }
804823}
@@ -934,6 +953,23 @@ fn run_package_review(json: bool, path: &str) -> ExitCode {
934953 }
935954}
936955
956+ fn run_package_diff ( json : bool , old_path : & str , new_path : & str ) -> ExitCode {
957+ let diff = match diff_package_dirs ( Path :: new ( old_path) , Path :: new ( new_path) ) {
958+ Ok ( diff) => diff,
959+ Err ( error) => {
960+ eprintln ! ( "{error}" ) ;
961+ return ExitCode :: from ( 2 ) ;
962+ }
963+ } ;
964+
965+ if json {
966+ println ! ( "{}" , format_package_diff_json( & diff) ) ;
967+ } else {
968+ print ! ( "{}" , format_package_diff_human( & diff) ) ;
969+ }
970+ ExitCode :: SUCCESS
971+ }
972+
937973struct ReviewMapSource {
938974 path : String ,
939975 contents : String ,
@@ -1011,4 +1047,5 @@ fn print_usage() {
10111047 eprintln ! ( " rsscript review [--json] --diff <old.rss> <new.rss>" ) ;
10121048 eprintln ! ( " rsscript review [--json] --map <file-or-directory>" ) ;
10131049 eprintln ! ( " rsscript package review [--json] <package-directory>" ) ;
1050+ eprintln ! ( " rsscript package diff [--json] <old-package-directory> <new-package-directory>" ) ;
10141051}
0 commit comments