Skip to content

Commit f78f1d4

Browse files
committed
Enabling implicit name in OptionArrayAttribute.
1 parent 994ec0a commit f78f1d4

File tree

7 files changed

+36
-5
lines changed

7 files changed

+36
-5
lines changed

CommandLine.sln.DotSettings.user

+1-1
Large diffs are not rendered by default.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Command Line Parser Library 1.9.7.0 stable for CLR.
1+
Command Line Parser Library 1.9.7.2 stable for CLR.
22
===
33
The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks defining switches, options and verb commands. It allows you to display an help screen with an high degree of customization and a simple way to report syntax errors to the end user. Everything that is boring and repetitive to be programmed stands up on library shoulders, letting developers concentrate on core logic.
44
__This library provides _hassle free_ command line parsing with a constantly updated API since 2005.__

Rakefile.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PRODUCT = "Command Line Parser Library"
22
DESCRIPTION = "The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks."
3-
VERSION = "1.9.7.0"
3+
VERSION = "1.9.7.2"
44
INF_VERSION = "1.9.7-stable"
55
AUTHOR = "Giacomo Stelluti Scala"
66
COPYRIGHT = "Copyright (c) 2005 - 2013 " + AUTHOR

src/SharedAssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
[assembly: AssemblyProduct("Command Line Parser Library")]
3030
[assembly: AssemblyCopyright("Copyright (c) 2005 - 2013 Giacomo Stelluti Scala")]
31-
[assembly: AssemblyVersion("1.9.7.0")]
32-
[assembly: AssemblyFileVersion("1.9.7.0")]
31+
[assembly: AssemblyVersion("1.9.7.2")]
32+
[assembly: AssemblyFileVersion("1.9.7.2")]
3333

3434
[assembly: AssemblyInformationalVersion("1.9.7-stable")]
3535
[assembly: NeutralResourcesLanguage("en-US")]

src/libcmdline/Attributes/OptionArrayAttribute.cs

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ namespace CommandLine
3333
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
3434
public sealed class OptionArrayAttribute : BaseOptionAttribute
3535
{
36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="CommandLine.OptionArrayAttribute"/> class.
38+
/// The default long name will be inferred from target property.
39+
/// </summary>
40+
public OptionArrayAttribute()
41+
{
42+
AutoLongName = true;
43+
}
44+
3645
/// <summary>
3746
/// Initializes a new instance of the <see cref="CommandLine.OptionArrayAttribute"/> class.
3847
/// </summary>

src/tests/Fakes/OptionsWithImplicitLongName.cs

+3
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ class OptionsWithImplicitLongName
1010

1111
[Option('b')]
1212
public int Bytes { get; set; }
13+
14+
[OptionArray]
15+
public int[] Offsets { get; set; }
1316
}
1417
}

src/tests/Unit/Attributes/OptionArrayAttributeFixture.cs

+19
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,24 @@ public void Should_correctly_parse_two_consecutive_arrays()
3434
options.Content.Should().HaveCount(c => c == 4);
3535
options.Content.Should().ContainInOrder(new uint[] { 5, 6, 7, 8 });
3636
}
37+
38+
[Fact]
39+
public void Should_use_property_name_as_long_name_if_omitted()
40+
{
41+
// Given
42+
var options = new OptionsWithImplicitLongName();
43+
var parser = new CommandLine.Parser();
44+
var arguments = new[] {
45+
"--offsets", "-2", "-1", "0", "1" , "2"
46+
};
47+
48+
// When
49+
var result = parser.ParseArguments(arguments, options);
50+
51+
// Than
52+
result.Should().Be(true);
53+
options.Offsets.Should().HaveCount(c => c == 5);
54+
options.Offsets.Should().ContainInOrder(new[] { -2, -1, 0, 1, 2 });
55+
}
3756
}
3857
}

0 commit comments

Comments
 (0)