@@ -117,31 +117,34 @@ public static class CommandLineParser
117
117
{
118
118
private const string FileSwitch = "/file:" ;
119
119
private const string ConfigSwitch = "/c:" ;
120
- private const string CopyrightSwitch = "/copyright:" ;
120
+ private const string CopyrightWithFileSwitch = "/copyright:" ;
121
121
private const string LanguageSwitch = "/lang:" ;
122
122
private const string RuleEnabledSwitch1 = "/rule+:" ;
123
123
private const string RuleEnabledSwitch2 = "/rule:" ;
124
124
private const string RuleDisabledSwitch = "/rule-:" ;
125
- private const string Usage =
125
+ private const string Usage =
126
126
@"CodeFormatter [/file:<filename>] [/lang:<language>] [/c:<config>[,<config>...]>]
127
- [/copyright: <file> | /nocopyright ] [/tables] [/nounicode]
127
+ [/copyright(+|-):[ <file>] ] [/tables] [/nounicode]
128
128
[/rule(+|-):rule1,rule2,...] [/verbose]
129
129
<project, solution or response file>
130
130
131
- /file - Only apply changes to files with specified name
132
- /lang - Specifies the language to use when a responsefile is
133
- specified. i.e. 'C#', 'Visual Basic', ... (default: 'C#')
134
- /c - Additional preprocessor configurations the formatter
135
- should run under.
136
- /copyright - Specifies file containing copyright header.
137
- Use ConvertTests to convert MSTest tests to xUnit.
138
- /nocopyright - Do not update the copyright message.
139
- /tables - Let tables opt out of formatting by defining
140
- DOTNET_FORMATTER
141
- /nounicode - Do not convert unicode strings to escape sequences
142
- /rule(+|-) - Enable (default) or disable the specified rule
143
- /rules - List the available rules
144
- /verbose - Verbose output
131
+ /file - Only apply changes to files with specified name
132
+ /lang - Specifies the language to use when a responsefile is
133
+ specified. i.e. 'C#', 'Visual Basic', ... (default: 'C#')
134
+ /c - Additional preprocessor configurations the formatter
135
+ should run under.
136
+ /copyright(+|-) - Enables or disables (default) updating the copyright
137
+ header in files, optionally specifying a file
138
+ containing a custom copyright header.
139
+ /nocopyright - Do not update the copyright message.
140
+ /tables - Let tables opt out of formatting by defining
141
+ DOTNET_FORMATTER
142
+ /nounicode - Do not convert unicode strings to escape sequences
143
+ /rule(+|-) - Enable (default) or disable the specified rule
144
+ /rules - List the available rules
145
+ /verbose - Verbose output
146
+
147
+ Use ConvertTests to convert MSTest tests to xUnit.
145
148
" ;
146
149
147
150
public static void PrintUsage ( )
@@ -163,7 +166,7 @@ public static CommandLineParseResult Parse(string[] args)
163
166
var formatTargets = new List < string > ( ) ;
164
167
var fileNames = new List < string > ( ) ;
165
168
var configBuilder = ImmutableArray . CreateBuilder < string [ ] > ( ) ;
166
- var copyrightHeader = FormattingDefaults . DefaultCopyrightHeader ;
169
+ var copyrightHeader = ImmutableArray < string > . Empty ;
167
170
var ruleMap = ImmutableDictionary < string , bool > . Empty ;
168
171
var language = LanguageNames . CSharp ;
169
172
var allowTables = false ;
@@ -172,15 +175,22 @@ public static CommandLineParseResult Parse(string[] args)
172
175
for ( int i = 0 ; i < args . Length ; i ++ )
173
176
{
174
177
string arg = args [ i ] ;
175
- if ( arg . StartsWith ( ConfigSwitch , StringComparison . OrdinalIgnoreCase ) )
178
+ if ( arg . StartsWith ( ConfigSwitch , comparison ) )
176
179
{
177
180
var all = arg . Substring ( ConfigSwitch . Length ) ;
178
181
var configs = all . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) ;
179
182
configBuilder . Add ( configs ) ;
180
183
}
181
- else if ( arg . StartsWith ( CopyrightSwitch , StringComparison . OrdinalIgnoreCase ) )
184
+ else if ( comparer . Equals ( arg , "/copyright+" ) || comparer . Equals ( arg , "/copyright" ) )
185
+ {
186
+ ruleMap = ruleMap . SetItem ( FormattingDefaults . CopyrightRuleName , true ) ;
187
+ copyrightHeader = FormattingDefaults . DefaultCopyrightHeader ;
188
+ }
189
+ else if ( arg . StartsWith ( CopyrightWithFileSwitch , comparison ) )
182
190
{
183
- var fileName = arg . Substring ( CopyrightSwitch . Length ) ;
191
+ ruleMap = ruleMap . SetItem ( FormattingDefaults . CopyrightRuleName , true ) ;
192
+
193
+ var fileName = arg . Substring ( CopyrightWithFileSwitch . Length ) ;
184
194
try
185
195
{
186
196
copyrightHeader = ImmutableArray . CreateRange ( File . ReadAllLines ( fileName ) ) ;
@@ -194,13 +204,14 @@ public static CommandLineParseResult Parse(string[] args)
194
204
return CommandLineParseResult . CreateError ( error ) ;
195
205
}
196
206
}
197
- else if ( arg . StartsWith ( LanguageSwitch , StringComparison . OrdinalIgnoreCase ) )
198
- {
199
- language = arg . Substring ( LanguageSwitch . Length ) ;
207
+ else if ( comparer . Equals ( arg , "/copyright-" ) || comparer . Equals ( arg , "/nocopyright" ) )
208
+ { // We still check /nocopyright for backwards compat
209
+
210
+ ruleMap = ruleMap . SetItem ( FormattingDefaults . CopyrightRuleName , false ) ;
200
211
}
201
- else if ( comparer . Equals ( arg , "/nocopyright" ) )
212
+ else if ( arg . StartsWith ( LanguageSwitch , comparison ) )
202
213
{
203
- ruleMap = ruleMap . SetItem ( FormattingDefaults . CopyrightRuleName , false ) ;
214
+ language = arg . Substring ( LanguageSwitch . Length ) ;
204
215
}
205
216
else if ( comparer . Equals ( arg , "/nounicode" ) )
206
217
{
0 commit comments