BadScript 2
Loading...
Searching...
No Matches
OptionSpecification.cs
Go to the documentation of this file.
1// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2
3using System;
4using System.Collections.Generic;
5using System.Linq;
6
7using CSharpx;
8
9namespace CommandLine.Core
10{
11 internal sealed class OptionSpecification : Specification
12 {
13 public OptionSpecification(string shortName,
14 string longName,
15 bool required,
16 string setName,
17 Maybe<int> min,
18 Maybe<int> max,
19 char separator,
20 Maybe<object> defaultValue,
21 string helpText,
22 string metaValue,
23 IEnumerable<string> enumValues,
24 Type conversionType,
25 TargetType targetType,
26 string group,
27 bool flagCounter = false,
28 bool hidden = false)
30 required,
31 min,
32 max,
33 defaultValue,
34 helpText,
35 metaValue,
36 enumValues,
37 conversionType,
38 conversionType == typeof(int) && flagCounter ? TargetType.Switch : targetType,
39 hidden
40 )
41 {
42 ShortName = shortName;
43 LongName = longName;
44 Separator = separator;
45 SetName = setName;
46 Group = group;
47 FlagCounter = flagCounter;
48 }
49
50 public string ShortName { get; }
51
52 public string LongName { get; }
53
54 public char Separator { get; }
55
56 public string SetName { get; }
57
58 public string Group { get; }
59
64 public bool FlagCounter { get; }
65
67 Type conversionType,
68 IEnumerable<string> enumValues)
69 {
70 return new OptionSpecification(attribute.ShortName,
71 attribute.LongName,
72 attribute.Required,
73 attribute.SetName,
74 attribute.Min == -1 ? Maybe.Nothing<int>() : Maybe.Just(attribute.Min),
75 attribute.Max == -1 ? Maybe.Nothing<int>() : Maybe.Just(attribute.Max),
76 attribute.Separator,
77 attribute.Default.ToMaybe(),
78 attribute.HelpText,
79 attribute.MetaValue,
80 enumValues,
81 conversionType,
82 conversionType.ToTargetType(),
83 attribute.Group,
84 attribute.FlagCounter,
85 attribute.Hidden
86 );
87 }
88
89 public static OptionSpecification NewSwitch(string shortName,
90 string longName,
91 bool required,
92 string helpText,
93 string metaValue,
94 bool hidden = false)
95 {
96 return new OptionSpecification(shortName,
97 longName,
98 required,
99 string.Empty,
100 Maybe.Nothing<int>(),
101 Maybe.Nothing<int>(),
102 '\0',
103 Maybe.Nothing<object>(),
104 helpText,
105 metaValue,
106 Enumerable.Empty<string>(),
107 typeof(bool),
108 TargetType.Switch,
109 string.Empty,
110 false,
111 hidden
112 );
113 }
114 }
115}
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
Definition Maybe.cs:33
int Min
When applied to System.Collections.Generic.IEnumerable<T> properties defines the lower range of items...
bool Required
Gets or sets a value indicating whether a command line option is required.
string MetaValue
Gets or sets mapped property meta value. Usually an uppercase hint of required value type.
int Max
When applied to System.Collections.Generic.IEnumerable<T> properties defines the upper range of items...
string HelpText
Gets or sets a short description of this command line option. Usually a sentence summary.
object Default
Gets or sets mapped property default value.
OptionSpecification(string shortName, string longName, bool required, string setName, Maybe< int > min, Maybe< int > max, char separator, Maybe< object > defaultValue, string helpText, string metaValue, IEnumerable< string > enumValues, Type conversionType, TargetType targetType, string group, bool flagCounter=false, bool hidden=false)
static OptionSpecification FromAttribute(OptionAttribute attribute, Type conversionType, IEnumerable< string > enumValues)
static OptionSpecification NewSwitch(string shortName, string longName, bool required, string helpText, string metaValue, bool hidden=false)
bool FlagCounter
Whether this is an int option that counts how many times a flag was set rather than taking a value on...
Models an option specification.
string Group
Gets or sets the option group name. When one or more options are grouped, at least one of them should...
char Separator
When applying attribute to System.Collections.Generic.IEnumerable<T> target properties,...
string SetName
Gets or sets the option's mutually exclusive set name.
bool FlagCounter
If true, this is an int option that counts how many times a flag was set (e.g. "-v -v -v" or "-vvv" w...
string ShortName
Gets a short name of this command line option, made of one character.
string LongName
Gets long name of this command line option. This name is usually a single english word.