diff --git a/src/CommandLineArgumentsParser/Arguments/RegexValueArgument.cs b/src/CommandLineArgumentsParser/Arguments/RegexValueArgument.cs index 3814880..277fc50 100644 --- a/src/CommandLineArgumentsParser/Arguments/RegexValueArgument.cs +++ b/src/CommandLineArgumentsParser/Arguments/RegexValueArgument.cs @@ -11,6 +11,7 @@ namespace CommandLineParser.Arguments public class RegexValueArgument : CertifiedValueArgument { private Regex regex; + private string sampleValue; /// /// Regular expression which the value must match @@ -20,6 +21,16 @@ public Regex Regex get { return regex; } set { regex = value; } } + + /// + /// Sample value that would be displayed to the user as a suggestion when + /// the user enters a wrong value. + /// + public string SampleValue + { + get { return sampleValue; } + set { sampleValue = value; } + } #region constructor @@ -78,8 +89,16 @@ protected override void Certify(string value) { if (!regex.IsMatch(value)) { - throw new CommandLineArgumentOutOfRangeException( - string.Format("Argument '{0}' does not match the regex pattern '{1}'.", value, regex), Name); + if (SampleValue == null) + { + throw new CommandLineArgumentOutOfRangeException( + string.Format("Argument '{0}' does not match the regex pattern '{1}'.", value, regex), Name); + } + else + { + throw new CommandLineArgumentOutOfRangeException( + string.Format("Argument '{0}' does not match the regex pattern '{1}'. An example of a valid value would be '{2}'.", value, regex, SampleValue), Name); + } } } } @@ -154,6 +173,22 @@ public object DefaultValue } } + /// + /// Sample value that would be displayed to the user as a suggestion when + /// the user enters a wrong value. + /// + public string SampleValue + { + get + { + return _argumentType.GetPropertyValue("SampleValue", Argument); + } + set + { + _argumentType.SetPropertyValue("SampleValue", Argument, value); + } + } + /// /// When set to true, argument can appear on the command line with or without value, e.g. both is allowed: /// diff --git a/src/CommandLineArgumentsParser/Arguments/ValueArgument.cs b/src/CommandLineArgumentsParser/Arguments/ValueArgument.cs index 39540a5..3973544 100644 --- a/src/CommandLineArgumentsParser/Arguments/ValueArgument.cs +++ b/src/CommandLineArgumentsParser/Arguments/ValueArgument.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections.Generic; using System.Globalization; using System.Reflection; @@ -407,15 +408,12 @@ public override void Init() public override void PrintValueInfo() { if (!AllowMultiple) + { Console.WriteLine(Messages.EXC_ARG_VALUE_PRINT, Name, _stringValue, _value, typeof(TValue).Name); + } else { - string valuesString = String.Empty; - foreach (TValue tvalue in _values) - { - valuesString += tvalue.ToString(); - - } + string valuesString = string.Join(", ", _values.Select(v => v.ToString()).ToArray()); Console.WriteLine(Messages.EXC_ARG_VALUE_PRINT_MULTIPLE, Name, Values.Count, valuesString, typeof(TValue).Name); } } diff --git a/src/CommandLineArgumentsParser/CommandLineArgumentsParser.csproj b/src/CommandLineArgumentsParser/CommandLineArgumentsParser.csproj index b6faa0d..5b701ae 100644 --- a/src/CommandLineArgumentsParser/CommandLineArgumentsParser.csproj +++ b/src/CommandLineArgumentsParser/CommandLineArgumentsParser.csproj @@ -20,7 +20,9 @@ false false CommandLineParser - 3.0.8 + 3.0.8.1 + 3.0.8.1 + 3.0.8.1