Skip to content

Commit

Permalink
Rename ICommandLineValidatable.Validate to ICommandLineProcessed.Proc…
Browse files Browse the repository at this point in the history
…ess and update documentation.
  • Loading branch information
rstarkov committed Sep 29, 2024
1 parent a77e330 commit 9ec3666
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Src/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ private static object parseCommandLine(string[] args, Type type, int i, Func<Con

try
{
if (ret is ICommandLineValidatable v)
v.Validate();
if (ret is ICommandLineProcessed v)
v.Process();
}
catch (CommandLineValidationException exc) when (exc.GenerateHelpFunc == null)
{
Expand Down
20 changes: 20 additions & 0 deletions Src/ICommandLineProcessed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace RT.CommandLine;

/// <summary>
/// Contains methods to post-process a class representing command-line options as populated by <see
/// cref="CommandLineParser"/>.</summary>
/// <remarks>
/// If an input doesn’t parse correctly, throw <see cref="CommandLineValidationException"/> with a helpful, descriptive
/// message that is displayed to the user.</remarks>
public interface ICommandLineProcessed
{
/// <summary>
/// When implemented in a class, performs application-specific post-processing of the options class.</summary>
/// <remarks>
/// When <see cref="CommandLineParser"/> invokes this method, all parsed commands and options have already been
/// populated. This method can thus alter the class in application-specific ways, perform further parsing, or further
/// validate the options for constraints such as mutual exclusivity. To report a validation error, this method should
/// throw a <see cref="CommandLineValidationException"/> with a helpful, descriptive message that is displayed to the
/// user.</remarks>
void Process();
}
17 changes: 0 additions & 17 deletions Src/ICommandLineValidatable.cs

This file was deleted.

12 changes: 6 additions & 6 deletions Tests/Test1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace RT.CommandLine.Tests;

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

class Test1Cmd : ICommandLineValidatable
class Test1Cmd : ICommandLineProcessed
{
[IsPositional, IsMandatory]
public string Base;
Expand All @@ -14,17 +14,17 @@ class Test1Cmd : ICommandLineValidatable

public static int ValidateCalled = 0;

public void Validate()
public void Process()
{
ValidateCalled++;
}
}

[CommandGroup]
abstract class Test1SubcommandBase : ICommandLineValidatable
abstract class Test1SubcommandBase : ICommandLineProcessed
{
public static int ValidateCalled = 0;
public abstract void Validate();
public abstract void Process();
}

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

public override void Validate()
public override void Process()
{
ValidateCalled++;
}
Expand All @@ -42,5 +42,5 @@ public override void Validate()
[CommandName("sub2")]
sealed class Test1Subcommand2 : Test1SubcommandBase
{
public override void Validate() { }
public override void Process() { }
}

0 comments on commit 9ec3666

Please sign in to comment.