Skip to content

Commit

Permalink
Merge pull request #39 from j-maly/vs2017
Browse files Browse the repository at this point in the history
Vs2017
  • Loading branch information
j-maly authored Apr 19, 2017
2 parents 5fea79d + 2edb20f commit 836e715
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
39 changes: 37 additions & 2 deletions src/CommandLineArgumentsParser/Arguments/RegexValueArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace CommandLineParser.Arguments
public class RegexValueArgument : CertifiedValueArgument<string>
{
private Regex regex;
private string sampleValue;

/// <summary>
/// Regular expression which the value must match
Expand All @@ -20,6 +21,16 @@ public Regex Regex
get { return regex; }
set { regex = value; }
}

/// <summary>
/// Sample value that would be displayed to the user as a suggestion when
/// the user enters a wrong value.
/// </summary>
public string SampleValue
{
get { return sampleValue; }
set { sampleValue = value; }
}

#region constructor

Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -154,6 +173,22 @@ public object DefaultValue
}
}

/// <summary>
/// Sample value that would be displayed to the user as a suggestion when
/// the user enters a wrong value.
/// </summary>
public string SampleValue
{
get
{
return _argumentType.GetPropertyValue<string>("SampleValue", Argument);
}
set
{
_argumentType.SetPropertyValue("SampleValue", Argument, value);
}
}

/// <summary>
/// When set to true, argument can appear on the command line with or without value, e.g. both is allowed:
/// <code>
Expand Down
10 changes: 4 additions & 6 deletions src/CommandLineArgumentsParser/Arguments/ValueArgument.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<RootNamespace>CommandLineParser</RootNamespace>
<Version>3.0.8</Version>
<Version>3.0.8.1</Version>
<AssemblyVersion>3.0.8.1</AssemblyVersion>
<FileVersion>3.0.8.1</FileVersion>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net20' ">
Expand Down

0 comments on commit 836e715

Please sign in to comment.