Skip to content

Commit 9ec3666

Browse files
committed
Rename ICommandLineValidatable.Validate to ICommandLineProcessed.Process and update documentation.
1 parent a77e330 commit 9ec3666

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

Src/CommandLineParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ private static object parseCommandLine(string[] args, Type type, int i, Func<Con
500500

501501
try
502502
{
503-
if (ret is ICommandLineValidatable v)
504-
v.Validate();
503+
if (ret is ICommandLineProcessed v)
504+
v.Process();
505505
}
506506
catch (CommandLineValidationException exc) when (exc.GenerateHelpFunc == null)
507507
{

Src/ICommandLineProcessed.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace RT.CommandLine;
2+
3+
/// <summary>
4+
/// Contains methods to post-process a class representing command-line options as populated by <see
5+
/// cref="CommandLineParser"/>.</summary>
6+
/// <remarks>
7+
/// If an input doesn’t parse correctly, throw <see cref="CommandLineValidationException"/> with a helpful, descriptive
8+
/// message that is displayed to the user.</remarks>
9+
public interface ICommandLineProcessed
10+
{
11+
/// <summary>
12+
/// When implemented in a class, performs application-specific post-processing of the options class.</summary>
13+
/// <remarks>
14+
/// When <see cref="CommandLineParser"/> invokes this method, all parsed commands and options have already been
15+
/// populated. This method can thus alter the class in application-specific ways, perform further parsing, or further
16+
/// validate the options for constraints such as mutual exclusivity. To report a validation error, this method should
17+
/// throw a <see cref="CommandLineValidationException"/> with a helpful, descriptive message that is displayed to the
18+
/// user.</remarks>
19+
void Process();
20+
}

Src/ICommandLineValidatable.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

Tests/Test1.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace RT.CommandLine.Tests;
44

55
#pragma warning disable CS0649 // Field is never assigned to and will always have its default value
66

7-
class Test1Cmd : ICommandLineValidatable
7+
class Test1Cmd : ICommandLineProcessed
88
{
99
[IsPositional, IsMandatory]
1010
public string Base;
@@ -14,17 +14,17 @@ class Test1Cmd : ICommandLineValidatable
1414

1515
public static int ValidateCalled = 0;
1616

17-
public void Validate()
17+
public void Process()
1818
{
1919
ValidateCalled++;
2020
}
2121
}
2222

2323
[CommandGroup]
24-
abstract class Test1SubcommandBase : ICommandLineValidatable
24+
abstract class Test1SubcommandBase : ICommandLineProcessed
2525
{
2626
public static int ValidateCalled = 0;
27-
public abstract void Validate();
27+
public abstract void Process();
2828
}
2929

3030
[CommandName("sub1")]
@@ -33,7 +33,7 @@ sealed class Test1Subcommand1 : Test1SubcommandBase
3333
[IsPositional, IsMandatory]
3434
public string ItemName;
3535

36-
public override void Validate()
36+
public override void Process()
3737
{
3838
ValidateCalled++;
3939
}
@@ -42,5 +42,5 @@ public override void Validate()
4242
[CommandName("sub2")]
4343
sealed class Test1Subcommand2 : Test1SubcommandBase
4444
{
45-
public override void Validate() { }
45+
public override void Process() { }
4646
}

0 commit comments

Comments
 (0)