@@ -15,15 +15,19 @@ namespace CodeFormatter
1515{
1616 internal static class Program
1717 {
18+ private const string FileSwitch = "/file:" ;
19+ private const string ConfigSwitch = "/c:" ;
20+ private const string CopyrightSwitch = "/copyright:" ;
21+
1822 private static int Main ( string [ ] args )
1923 {
2024 if ( args . Length < 1 )
2125 {
22- Console . WriteLine ( "CodeFormatter <project or solution> [<rule types>] [/file:<filename>] [/nocopyright] [/c:<config1,config2>" ) ;
26+ Console . WriteLine ( "CodeFormatter <project or solution> [<rule types>] [/file:<filename>] [/nocopyright] [/c:<config1,config2> [/copyright:file] " ) ;
2327 Console . WriteLine ( " <rule types> - Rule types to use in addition to the default ones." ) ;
2428 Console . WriteLine ( " Use ConvertTests to convert MSTest tests to xUnit." ) ;
2529 Console . WriteLine ( " <filename> - Only apply changes to files with specified name." ) ;
26- Console . WriteLine ( " <configs> - Additional preprocessor configurations the formatter" )
30+ Console . WriteLine ( " <configs> - Additional preprocessor configurations the formatter" ) ;
2731 Console . WriteLine ( " should run under" ) ;
2832 return - 1 ;
2933 }
@@ -38,27 +42,41 @@ private static int Main(string[] args)
3842 var fileNamesBuilder = ImmutableArray . CreateBuilder < string > ( ) ;
3943 var ruleTypeBuilder = ImmutableArray . CreateBuilder < string > ( ) ;
4044 var configBuilder = ImmutableArray . CreateBuilder < string [ ] > ( ) ;
45+ var copyrightHeader = FormattingConstants . DefaultCopyrightHeader ;
4146 var comparer = StringComparer . OrdinalIgnoreCase ;
42- var disableCopyright = false ;
4347
4448 for ( int i = 1 ; i < args . Length ; i ++ )
4549 {
4650 string arg = args [ i ] ;
47- if ( arg . StartsWith ( "/file:" , StringComparison . OrdinalIgnoreCase ) )
51+ if ( arg . StartsWith ( FileSwitch , StringComparison . OrdinalIgnoreCase ) )
4852 {
49- var all = arg . Substring ( 6 ) ;
53+ var all = arg . Substring ( FileSwitch . Length ) ;
5054 var files = all . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) ;
5155 fileNamesBuilder . AddRange ( files ) ;
5256 }
53- else if ( arg . StartsWith ( "/c:" , StringComparison . OrdinalIgnoreCase ) )
57+ else if ( arg . StartsWith ( ConfigSwitch , StringComparison . OrdinalIgnoreCase ) )
5458 {
55- var all = arg . Substring ( 3 ) ;
59+ var all = arg . Substring ( ConfigSwitch . Length ) ;
5660 var configs = all . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) ;
5761 configBuilder . Add ( configs ) ;
5862 }
63+ else if ( arg . StartsWith ( CopyrightSwitch , StringComparison . OrdinalIgnoreCase ) )
64+ {
65+ var fileName = arg . Substring ( CopyrightSwitch . Length ) ;
66+ try
67+ {
68+ copyrightHeader = ImmutableArray . CreateRange ( File . ReadAllLines ( fileName ) ) ;
69+ }
70+ catch ( Exception ex )
71+ {
72+ Console . Error . WriteLine ( "Could not read {0}" , fileName ) ;
73+ Console . Error . WriteLine ( ex . Message ) ;
74+ return - 1 ;
75+ }
76+ }
5977 else if ( comparer . Equals ( arg , "/nocopyright" ) )
6078 {
61- disableCopyright = true ;
79+ copyrightHeader = ImmutableArray < string > . Empty ;
6280 }
6381 else
6482 {
@@ -76,7 +94,7 @@ private static int Main(string[] args)
7694 ruleTypeBuilder . ToImmutableArray ( ) ,
7795 fileNamesBuilder . ToImmutableArray ( ) ,
7896 configBuilder . ToImmutableArray ( ) ,
79- disableCopyright ,
97+ copyrightHeader ,
8098 ct ) . Wait ( ct ) ;
8199 Console . WriteLine ( "Completed formatting." ) ;
82100 return 0 ;
@@ -87,18 +105,14 @@ private static async Task RunAsync(
87105 ImmutableArray < string > ruleTypes ,
88106 ImmutableArray < string > fileNames ,
89107 ImmutableArray < string [ ] > preprocessorConfigurations ,
90- bool disableCopright ,
108+ ImmutableArray < string > copyrightHeader ,
91109 CancellationToken cancellationToken )
92110 {
93111 var workspace = MSBuildWorkspace . Create ( ) ;
94112 var engine = FormattingEngine . Create ( ruleTypes ) ;
95113 engine . PreprocessorConfigurations = preprocessorConfigurations ;
96114 engine . FileNames = fileNames ;
97-
98- if ( disableCopright )
99- {
100- engine . CopyrightHeader = ImmutableArray < string > . Empty ;
101- }
115+ engine . CopyrightHeader = copyrightHeader ;
102116
103117 string extension = Path . GetExtension ( projectOrSolutionPath ) ;
104118 if ( StringComparer . OrdinalIgnoreCase . Equals ( extension , ".sln" ) )
0 commit comments