Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vs2017 #39

Merged
merged 2 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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