@@ -117,31 +117,34 @@ public static class CommandLineParser
117117 {
118118 private const string FileSwitch = "/file:" ;
119119 private const string ConfigSwitch = "/c:" ;
120- private const string CopyrightSwitch = "/copyright:" ;
120+ private const string CopyrightWithFileSwitch = "/copyright:" ;
121121 private const string LanguageSwitch = "/lang:" ;
122122 private const string RuleEnabledSwitch1 = "/rule+:" ;
123123 private const string RuleEnabledSwitch2 = "/rule:" ;
124124 private const string RuleDisabledSwitch = "/rule-:" ;
125- private const string Usage =
125+ private const string Usage =
126126@"CodeFormatter [/file:<filename>] [/lang:<language>] [/c:<config>[,<config>...]>]
127- [/copyright: <file> | /nocopyright ] [/tables] [/nounicode]
127+ [/copyright(+|-):[ <file>] ] [/tables] [/nounicode]
128128 [/rule(+|-):rule1,rule2,...] [/verbose]
129129 <project, solution or response file>
130130
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.
145148" ;
146149
147150 public static void PrintUsage ( )
@@ -163,7 +166,7 @@ public static CommandLineParseResult Parse(string[] args)
163166 var formatTargets = new List < string > ( ) ;
164167 var fileNames = new List < string > ( ) ;
165168 var configBuilder = ImmutableArray . CreateBuilder < string [ ] > ( ) ;
166- var copyrightHeader = FormattingDefaults . DefaultCopyrightHeader ;
169+ var copyrightHeader = ImmutableArray < string > . Empty ;
167170 var ruleMap = ImmutableDictionary < string , bool > . Empty ;
168171 var language = LanguageNames . CSharp ;
169172 var allowTables = false ;
@@ -178,9 +181,16 @@ public static CommandLineParseResult Parse(string[] args)
178181 var configs = all . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) ;
179182 configBuilder . Add ( configs ) ;
180183 }
181- else if ( arg . StartsWith ( CopyrightSwitch , comparison ) )
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 ) )
182190 {
183- var fileName = arg . Substring ( CopyrightSwitch . Length ) ;
191+ ruleMap = ruleMap . SetItem ( FormattingDefaults . CopyrightRuleName , true ) ;
192+
193+ var fileName = arg . Substring ( CopyrightWithFileSwitch . Length ) ;
184194 try
185195 {
186196 copyrightHeader = ImmutableArray . CreateRange ( File . ReadAllLines ( fileName ) ) ;
@@ -194,8 +204,9 @@ public static CommandLineParseResult Parse(string[] args)
194204 return CommandLineParseResult . CreateError ( error ) ;
195205 }
196206 }
197- else if ( comparer . Equals ( arg , "/nocopyright" ) )
198- {
207+ else if ( comparer . Equals ( arg , "/copyright-" ) || comparer . Equals ( arg , "/nocopyright" ) )
208+ { // We still check /nocopyright for backwards compat
209+
199210 ruleMap = ruleMap . SetItem ( FormattingDefaults . CopyrightRuleName , false ) ;
200211 }
201212 else if ( arg . StartsWith ( LanguageSwitch , comparison ) )
0 commit comments