From 9ec3666152382193913b4561174354481faca003 Mon Sep 17 00:00:00 2001 From: Roman Starkov Date: Sun, 29 Sep 2024 13:17:53 +0100 Subject: [PATCH] Rename ICommandLineValidatable.Validate to ICommandLineProcessed.Process and update documentation. --- Src/CommandLineParser.cs | 4 ++-- Src/ICommandLineProcessed.cs | 20 ++++++++++++++++++++ Src/ICommandLineValidatable.cs | 17 ----------------- Tests/Test1.cs | 12 ++++++------ 4 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 Src/ICommandLineProcessed.cs delete mode 100644 Src/ICommandLineValidatable.cs diff --git a/Src/CommandLineParser.cs b/Src/CommandLineParser.cs index c4eaf30..a169d00 100644 --- a/Src/CommandLineParser.cs +++ b/Src/CommandLineParser.cs @@ -500,8 +500,8 @@ private static object parseCommandLine(string[] args, Type type, int i, Func +/// Contains methods to post-process a class representing command-line options as populated by . +/// +/// If an input doesn’t parse correctly, throw with a helpful, descriptive +/// message that is displayed to the user. +public interface ICommandLineProcessed +{ + /// + /// When implemented in a class, performs application-specific post-processing of the options class. + /// + /// When 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 with a helpful, descriptive message that is displayed to the + /// user. + void Process(); +} diff --git a/Src/ICommandLineValidatable.cs b/Src/ICommandLineValidatable.cs deleted file mode 100644 index 711ba3a..0000000 --- a/Src/ICommandLineValidatable.cs +++ /dev/null @@ -1,17 +0,0 @@ -using RT.Util.Consoles; - -namespace RT.CommandLine; - -/// -/// Contains methods to validate a set of parameters passed by the user on the command-line and parsed by . -/// -/// If an input doesn’t parse correctly, throw with a helpful, descriptive -/// message that is displayed to the user. -public interface ICommandLineValidatable -{ - /// - /// When overridden in a derived class, returns an error message if the contents of the class are invalid, otherwise - /// returns null. - void Validate(); -} diff --git a/Tests/Test1.cs b/Tests/Test1.cs index d1808e2..5594072 100644 --- a/Tests/Test1.cs +++ b/Tests/Test1.cs @@ -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; @@ -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")] @@ -33,7 +33,7 @@ sealed class Test1Subcommand1 : Test1SubcommandBase [IsPositional, IsMandatory] public string ItemName; - public override void Validate() + public override void Process() { ValidateCalled++; } @@ -42,5 +42,5 @@ public override void Validate() [CommandName("sub2")] sealed class Test1Subcommand2 : Test1SubcommandBase { - public override void Validate() { } + public override void Process() { } }