@@ -19,6 +19,8 @@ namespace Microsoft.CodeAnalysis.Tools
1919 internal class Program
2020 {
2121 private static readonly string [ ] _verbosityLevels = new [ ] { "q" , "quiet" , "m" , "minimal" , "n" , "normal" , "d" , "detailed" , "diag" , "diagnostic" } ;
22+ internal const int UnhandledExceptionExitCode = 1 ;
23+ internal const int CheckFailedExitCode = 2 ;
2224
2325 private static async Task < int > Main ( string [ ] args )
2426 {
@@ -33,8 +35,7 @@ private static async Task<int> Main(string[] args)
3335 . AddOption ( new Option ( new [ ] { "--folder" , "-f" } , Resources . The_folder_to_operate_on_Cannot_be_used_with_the_workspace_option , new Argument < string > ( ( ) => null ) ) )
3436 . AddOption ( new Option ( new [ ] { "--workspace" , "-w" } , Resources . The_solution_or_project_file_to_operate_on_If_a_file_is_not_specified_the_command_will_search_the_current_directory_for_one , new Argument < string > ( ( ) => null ) ) )
3537 . AddOption ( new Option ( new [ ] { "--verbosity" , "-v" } , Resources . Set_the_verbosity_level_Allowed_values_are_quiet_minimal_normal_detailed_and_diagnostic , new Argument < string > ( ) { Arity = ArgumentArity . ExactlyOne } . FromAmong ( _verbosityLevels ) ) )
36- . AddOption ( new Option ( new [ ] { "--dry-run" } , Resources . Format_files_but_do_not_save_changes_to_disk , new Argument < bool > ( ) ) )
37- . AddOption ( new Option ( new [ ] { "--check" } , Resources . Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted , new Argument < bool > ( ) ) )
38+ . AddOption ( new Option ( new [ ] { "--check" , "--dry-run" } , Resources . Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted , new Argument < bool > ( ) ) )
3839 . AddOption ( new Option ( new [ ] { "--include" , "--files" } , Resources . A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty , new Argument < string > ( ( ) => null ) ) )
3940 . AddOption ( new Option ( new [ ] { "--exclude" } , Resources . A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting , new Argument < string > ( ( ) => null ) ) )
4041 . AddOption ( new Option ( new [ ] { "--report" } , Resources . Accepts_a_file_path_which_if_provided_will_produce_a_format_report_json_file_in_the_given_directory , new Argument < string > ( ( ) => null ) ) )
@@ -44,7 +45,7 @@ private static async Task<int> Main(string[] args)
4445 return await parser . InvokeAsync ( args ) . ConfigureAwait ( false ) ;
4546 }
4647
47- public static async Task < int > Run ( string folder , string workspace , string verbosity , bool dryRun , bool check , string include , string exclude , string report , IConsole console = null )
48+ public static async Task < int > Run ( string folder , string workspace , string verbosity , bool check , string include , string exclude , string report , IConsole console = null )
4849 {
4950 // Setup logging.
5051 var serviceCollection = new ServiceCollection ( ) ;
@@ -121,7 +122,7 @@ public static async Task<int> Run(string folder, string workspace, string verbos
121122 workspacePath ,
122123 workspaceType ,
123124 logLevel ,
124- saveFormattedFiles : ! dryRun ,
125+ saveFormattedFiles : ! check ,
125126 changesAreErrors : check ,
126127 pathsToInclude ,
127128 pathsToExclude ,
@@ -137,11 +138,11 @@ public static async Task<int> Run(string folder, string workspace, string verbos
137138 catch ( FileNotFoundException fex )
138139 {
139140 logger . LogError ( fex . Message ) ;
140- return 1 ;
141+ return UnhandledExceptionExitCode ;
141142 }
142143 catch ( OperationCanceledException )
143144 {
144- return 1 ;
145+ return UnhandledExceptionExitCode ;
145146 }
146147 finally
147148 {
@@ -159,7 +160,7 @@ internal static int GetExitCode(WorkspaceFormatResult formatResult, bool check)
159160 return formatResult . ExitCode ;
160161 }
161162
162- return formatResult . FilesFormatted == 0 ? 0 : 1 ;
163+ return formatResult . FilesFormatted == 0 ? 0 : CheckFailedExitCode ;
163164 }
164165
165166 internal static LogLevel GetLogLevel ( string verbosity )
0 commit comments