Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit ee0effe

Browse files
committed
Added support for /help (short form: /?) switch
1 parent bbe1a66 commit ee0effe

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/CodeFormatter/CommandLineParser.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public enum Operation
1515
{
1616
Format,
1717
ListRules,
18+
ShowHelp
1819
}
1920

2021
public sealed class CommandLineOptions
@@ -30,6 +31,18 @@ public sealed class CommandLineOptions
3031
allowTables: false,
3132
verbose: false);
3233

34+
public static readonly CommandLineOptions ShowHelp = new CommandLineOptions(
35+
Operation.ShowHelp,
36+
ImmutableArray<string[]>.Empty,
37+
ImmutableArray<string>.Empty,
38+
ImmutableDictionary<string, bool>.Empty,
39+
ImmutableArray<string>.Empty,
40+
ImmutableArray<string>.Empty,
41+
null,
42+
allowTables: false,
43+
verbose: false);
44+
45+
3346
public readonly Operation Operation;
3447
public readonly ImmutableArray<string[]> PreprocessorConfigurations;
3548
public readonly ImmutableArray<string> CopyrightHeader;
@@ -143,8 +156,7 @@ containing a custom copyright header.
143156
/rule(+|-) - Enable (default) or disable the specified rule
144157
/rules - List the available rules
145158
/verbose - Verbose output
146-
147-
Use ConvertTests to convert MSTest tests to xUnit.
159+
/help - Displays this usage message (short form: /?)
148160
";
149161

150162
public static void PrintUsage()
@@ -245,6 +257,10 @@ public static CommandLineParseResult Parse(string[] args)
245257
{
246258
return CommandLineParseResult.CreateSuccess(CommandLineOptions.ListRules);
247259
}
260+
else if (comparer.Equals(arg, "/?") || comparer.Equals(arg, "/help"))
261+
{
262+
return CommandLineParseResult.CreateSuccess(CommandLineOptions.ShowHelp);
263+
}
248264
else if (arg.StartsWith("/", comparison))
249265
{
250266
return CommandLineParseResult.CreateError($"Unrecognized option \"{arg}\"");

src/CodeFormatter/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ private static int Main(string[] args)
3131
int exitCode;
3232
switch (options.Operation)
3333
{
34+
case Operation.ShowHelp:
35+
CommandLineParser.PrintUsage();
36+
exitCode = 0;
37+
break;
38+
3439
case Operation.ListRules:
3540
RunListRules();
3641
exitCode = 0;

src/Microsoft.DotNet.CodeFormatting.Tests/CommandLineParserTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ public void NoCopyright()
108108
Assert.Equal(new[] { "test.csproj" }, options.FormatTargets);
109109
}
110110

111+
112+
[Fact]
113+
public void Help()
114+
{
115+
var options = Parse("/help");
116+
Assert.Equal(options.Operation, Operation.ShowHelp);
117+
}
118+
119+
[Fact]
120+
public void HelpShortForm()
121+
{
122+
var options = Parse("/?");
123+
Assert.Equal(options.Operation, Operation.ShowHelp);
124+
}
125+
126+
[Fact]
127+
public void HelpWithOtherwiseValidArguments()
128+
{
129+
var options = Parse("test.csproj", "/nocopyright", "/help");
130+
Assert.Equal(options.Operation, Operation.ShowHelp);
131+
}
132+
111133
[Fact]
112134
public void CopyrightEnable1()
113135
{

0 commit comments

Comments
 (0)