Skip to content

Commit ff61b69

Browse files
committed
Modify type of Group to string instead of `Mayb<string>'
1 parent 4274c25 commit ff61b69

File tree

8 files changed

+28
-22
lines changed

8 files changed

+28
-22
lines changed

src/CommandLine/Core/OptionSpecification.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ sealed class OptionSpecification : Specification
1313
private readonly string longName;
1414
private readonly char separator;
1515
private readonly string setName;
16-
private readonly Maybe<string> group;
16+
private readonly string group;
1717

1818
public OptionSpecification(string shortName, string longName, bool required, string setName, Maybe<int> min, Maybe<int> max,
1919
char separator, Maybe<object> defaultValue, string helpText, string metaValue, IEnumerable<string> enumValues,
20-
Type conversionType, TargetType targetType, Maybe<string> group, bool hidden = false)
21-
: base(SpecificationType.Option, required, min, max, defaultValue, helpText, metaValue, enumValues, conversionType, targetType, hidden)
20+
Type conversionType, TargetType targetType, string group, bool hidden = false)
21+
: base(SpecificationType.Option,
22+
required, min, max, defaultValue, helpText, metaValue, enumValues, conversionType, targetType, hidden)
2223
{
2324
this.shortName = shortName;
2425
this.longName = longName;
@@ -43,14 +44,14 @@ public static OptionSpecification FromAttribute(OptionAttribute attribute, Type
4344
enumValues,
4445
conversionType,
4546
conversionType.ToTargetType(),
46-
string.IsNullOrWhiteSpace(attribute.Group) ? Maybe.Nothing<string>() : Maybe.Just(attribute.Group),
47+
attribute.Group,
4748
attribute.Hidden);
4849
}
4950

5051
public static OptionSpecification NewSwitch(string shortName, string longName, bool required, string helpText, string metaValue, bool hidden = false)
5152
{
5253
return new OptionSpecification(shortName, longName, required, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(),
53-
'\0', Maybe.Nothing<object>(), helpText, metaValue, Enumerable.Empty<string>(), typeof(bool), TargetType.Switch, Maybe.Nothing<string>(), hidden);
54+
'\0', Maybe.Nothing<object>(), helpText, metaValue, Enumerable.Empty<string>(), typeof(bool), TargetType.Switch, string.Empty, hidden);
5455
}
5556

5657
public string ShortName
@@ -73,7 +74,7 @@ public string SetName
7374
get { return setName; }
7475
}
7576

76-
public Maybe<string> Group
77+
public string Group
7778
{
7879
get { return group; }
7980
}

src/CommandLine/Core/SpecificationPropertyRules.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ private static Func<IEnumerable<SpecificationProperty>, IEnumerable<Error>> Enfo
3232
from sp in specProps
3333
where sp.Specification.IsOption()
3434
let o = (OptionSpecification)sp.Specification
35-
where o.Group.IsJust()
35+
where o.Group.Length > 0
3636
select new
3737
{
3838
Option = o,
3939
Value = sp.Value
4040
};
4141

4242
var groups = from o in optionsValues
43-
group o by o.Option.Group.GetValueOrDefault(null) into g
43+
group o by o.Option.Group into g
4444
select g;
4545

4646
var errorGroups = groups.Where(gr => gr.All(g => g.Value.IsNothing()));
@@ -101,7 +101,7 @@ where sp.Specification.Required
101101
where sp.Value.IsNothing()
102102
let o = (OptionSpecification)sp.Specification
103103
where o.SetName.Length > 0
104-
where o.Group.IsNothing()
104+
where o.Group.Length == 0
105105
where setWithRequiredValue.ContainsIfNotEmpty(o.SetName)
106106
select sp.Specification;
107107
var missing =
@@ -114,7 +114,7 @@ where sp.Specification.Required
114114
where sp.Value.IsNothing()
115115
let o = (OptionSpecification)sp.Specification
116116
where o.SetName.Length == 0
117-
where o.Group.IsNothing()
117+
where o.Group.Length == 0
118118
select sp.Specification)
119119
.Concat(
120120
from sp in specProps

src/CommandLine/OptionAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public sealed class OptionAttribute : BaseAttribute
1616
private readonly string shortName;
1717
private string setName;
1818
private char separator;
19-
private string group;
19+
private string group=string.Empty;
2020

2121
private OptionAttribute(string shortName, string longName) : base()
2222
{

src/CommandLine/Text/HelpText.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,12 @@ private HelpText AddOption(string requiredWord, string optionGroupWord, int maxL
875875
{
876876
OptionSpecification GetOptionGroupSpecification()
877877
{
878-
if (specification.Tag == SpecificationType.Option && specification is OptionSpecification optionSpecification && optionSpecification.Group.IsJust())
878+
if (specification.Tag == SpecificationType.Option &&
879+
specification is OptionSpecification optionSpecification &&
880+
optionSpecification.Group.Length > 0
881+
)
882+
883+
879884
{
880885
return optionSpecification;
881886
}
@@ -912,7 +917,7 @@ OptionSpecification GetOptionGroupSpecification()
912917

913918
if (optionGroupSpecification != null)
914919
{
915-
optionHelpText = "({0}: {1}) ".FormatInvariant(optionGroupWord, optionGroupSpecification.Group.GetValueOrDefault(null)) + optionHelpText;
920+
optionHelpText = "({0}: {1}) ".FormatInvariant(optionGroupWord, optionGroupSpecification.Group) + optionHelpText;
916921
}
917922

918923
//note that we need to indent trim the start of the string because it's going to be

tests/CommandLine.Tests/Unit/Core/NameLookupTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void Lookup_name_of_sequence_option_with_separator()
2121
// Fixture setup
2222
var expected = Maybe.Just(".");
2323
var specs = new[] { new OptionSpecification(string.Empty, "string-seq",
24-
false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '.', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<string>), TargetType.Sequence, Maybe.Nothing<string>())};
24+
false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '.', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<string>), TargetType.Sequence, string.Empty)};
2525

2626
// Exercize system
2727
var result = NameLookup.HavingSeparator("string-seq", specs, StringComparer.Ordinal);
@@ -39,7 +39,7 @@ public void Get_name_from_option_specification()
3939

4040
// Fixture setup
4141
var expected = new NameInfo(ShortName, LongName);
42-
var spec = new OptionSpecification(ShortName, LongName, false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '.', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<string>), TargetType.Sequence, Maybe.Nothing<string>());
42+
var spec = new OptionSpecification(ShortName, LongName, false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '.', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<string>), TargetType.Sequence, string.Empty);
4343

4444
// Exercize system
4545
var result = spec.FromOptionSpecification();

tests/CommandLine.Tests/Unit/Core/OptionMapperTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void Map_boolean_switch_creates_boolean_value()
3232
var specProps = new[]
3333
{
3434
SpecificationProperty.Create(
35-
new OptionSpecification("x", string.Empty, false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', Maybe.Nothing<object>(), string.Empty, string.Empty, new List<string>(), typeof(bool), TargetType.Switch, Maybe.Nothing<string>()),
35+
new OptionSpecification("x", string.Empty, false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', Maybe.Nothing<object>(), string.Empty, string.Empty, new List<string>(), typeof(bool), TargetType.Switch, string.Empty),
3636
typeof(Simple_Options).GetProperties().Single(p => p.Name.Equals("BoolValue", StringComparison.Ordinal)),
3737
Maybe.Nothing<object>())
3838
};

tests/CommandLine.Tests/Unit/Core/TokenPartitionerTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public void Partition_sequence_returns_sequence()
2424
};
2525
var specs = new[]
2626
{
27-
new OptionSpecification(string.Empty, "stringvalue", false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(string), TargetType.Scalar, Maybe.Nothing<string>()),
28-
new OptionSpecification("i", string.Empty, false, string.Empty, Maybe.Just(3), Maybe.Just(4), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<int>), TargetType.Sequence, Maybe.Nothing<string>())
27+
new OptionSpecification(string.Empty, "stringvalue", false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(string), TargetType.Scalar, string.Empty),
28+
new OptionSpecification("i", string.Empty, false, string.Empty, Maybe.Just(3), Maybe.Just(4), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<int>), TargetType.Sequence, string.Empty)
2929
};
3030

3131
// Exercize system
@@ -51,8 +51,8 @@ public void Partition_sequence_returns_sequence_with_duplicates()
5151
};
5252
var specs = new[]
5353
{
54-
new OptionSpecification(string.Empty, "stringvalue", false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(string), TargetType.Scalar, Maybe.Nothing<string>()),
55-
new OptionSpecification("i", string.Empty, false, string.Empty, Maybe.Just(3), Maybe.Just(4), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<int>), TargetType.Sequence, Maybe.Nothing<string>())
54+
new OptionSpecification(string.Empty, "stringvalue", false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(string), TargetType.Scalar, string.Empty),
55+
new OptionSpecification("i", string.Empty, false, string.Empty, Maybe.Just(3), Maybe.Just(4), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<int>), TargetType.Sequence, string.Empty)
5656
};
5757

5858
// Exercize system

tests/CommandLine.Tests/Unit/Core/TokenizerTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void Explode_scalar_with_separator_in_odd_args_input_returns_sequence()
2626
var expectedTokens = new[] { Token.Name("i"), Token.Value("10"), Token.Name("string-seq"),
2727
Token.Value("aaa"), Token.Value("bb"), Token.Value("cccc"), Token.Name("switch") };
2828
var specs = new[] { new OptionSpecification(string.Empty, "string-seq",
29-
false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), ',', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<string>), TargetType.Sequence, Maybe.Nothing<string>())};
29+
false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), ',', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<string>), TargetType.Sequence, string.Empty)};
3030

3131
// Exercize system
3232
var result =
@@ -49,7 +49,7 @@ public void Explode_scalar_with_separator_in_even_args_input_returns_sequence()
4949
var expectedTokens = new[] { Token.Name("x"), Token.Name("string-seq"),
5050
Token.Value("aaa"), Token.Value("bb"), Token.Value("cccc"), Token.Name("switch") };
5151
var specs = new[] { new OptionSpecification(string.Empty, "string-seq",
52-
false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), ',', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<string>), TargetType.Sequence, Maybe.Nothing<string>())};
52+
false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), ',', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<string>), TargetType.Sequence, string.Empty)};
5353

5454
// Exercize system
5555
var result =

0 commit comments

Comments
 (0)