@@ -14,18 +14,20 @@ sealed class OptionSpecification : Specification
1414 private readonly char separator ;
1515 private readonly string setName ;
1616 private readonly string group ;
17+ private readonly bool flagCounter ;
1718
1819 public OptionSpecification ( string shortName , string longName , bool required , string setName , Maybe < int > min , Maybe < int > max ,
1920 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 )
2122 : 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 )
2324 {
2425 this . shortName = shortName ;
2526 this . longName = longName ;
2627 this . separator = separator ;
2728 this . setName = setName ;
2829 this . group = group ;
30+ this . flagCounter = flagCounter ;
2931 }
3032
3133 public static OptionSpecification FromAttribute ( OptionAttribute attribute , Type conversionType , IEnumerable < string > enumValues )
@@ -45,13 +47,14 @@ public static OptionSpecification FromAttribute(OptionAttribute attribute, Type
4547 conversionType ,
4648 conversionType . ToTargetType ( ) ,
4749 attribute . Group ,
50+ attribute . FlagCounter ,
4851 attribute . Hidden ) ;
4952 }
5053
5154 public static OptionSpecification NewSwitch ( string shortName , string longName , bool required , string helpText , string metaValue , bool hidden = false )
5255 {
5356 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 ) ;
5558 }
5659
5760 public string ShortName
@@ -78,5 +81,13 @@ public string Group
7881 {
7982 get { return group ; }
8083 }
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+ }
8192 }
8293}
0 commit comments