@@ -14,18 +14,20 @@ sealed class OptionSpecification : Specification
14
14
private readonly char separator ;
15
15
private readonly string setName ;
16
16
private readonly string group ;
17
+ private readonly bool flagCounter ;
17
18
18
19
public OptionSpecification ( string shortName , string longName , bool required , string setName , Maybe < int > min , Maybe < int > max ,
19
20
char separator , Maybe < object > defaultValue , string helpText , string metaValue , IEnumerable < string > enumValues ,
20
- Type conversionType , TargetType targetType , string group , bool hidden = false )
21
+ Type conversionType , TargetType targetType , string group , bool flagCounter = false , bool hidden = false )
21
22
: base ( SpecificationType . Option ,
22
- required , min , max , defaultValue , helpText , metaValue , enumValues , conversionType , targetType , hidden )
23
+ required , min , max , defaultValue , helpText , metaValue , enumValues , conversionType , conversionType == typeof ( int ) && flagCounter ? TargetType . Switch : targetType , hidden )
23
24
{
24
25
this . shortName = shortName ;
25
26
this . longName = longName ;
26
27
this . separator = separator ;
27
28
this . setName = setName ;
28
29
this . group = group ;
30
+ this . flagCounter = flagCounter ;
29
31
}
30
32
31
33
public static OptionSpecification FromAttribute ( OptionAttribute attribute , Type conversionType , IEnumerable < string > enumValues )
@@ -45,13 +47,14 @@ public static OptionSpecification FromAttribute(OptionAttribute attribute, Type
45
47
conversionType ,
46
48
conversionType . ToTargetType ( ) ,
47
49
attribute . Group ,
50
+ attribute . FlagCounter ,
48
51
attribute . Hidden ) ;
49
52
}
50
53
51
54
public static OptionSpecification NewSwitch ( string shortName , string longName , bool required , string helpText , string metaValue , bool hidden = false )
52
55
{
53
56
return new OptionSpecification ( shortName , longName , required , string . Empty , Maybe . Nothing < int > ( ) , Maybe . Nothing < int > ( ) ,
54
- '\0 ' , Maybe . Nothing < object > ( ) , helpText , metaValue , Enumerable . Empty < string > ( ) , typeof ( bool ) , TargetType . Switch , string . Empty , hidden ) ;
57
+ '\0 ' , Maybe . Nothing < object > ( ) , helpText , metaValue , Enumerable . Empty < string > ( ) , typeof ( bool ) , TargetType . Switch , string . Empty , false , hidden ) ;
55
58
}
56
59
57
60
public string ShortName
@@ -78,5 +81,13 @@ public string Group
78
81
{
79
82
get { return group ; }
80
83
}
84
+
85
+ /// <summary>
86
+ /// Whether this is an int option that counts how many times a flag was set rather than taking a value on the command line
87
+ /// </summary>
88
+ public bool FlagCounter
89
+ {
90
+ get { return flagCounter ; }
91
+ }
81
92
}
82
93
}
0 commit comments