-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy pathOptionSpecification.cs
More file actions
68 lines (58 loc) · 2.95 KB
/
OptionSpecification.cs
File metadata and controls
68 lines (58 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using CSharpx;
namespace CommandLine.Core
{
sealed class OptionSpecification : Specification
{
public 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)
: base(SpecificationType.Option,
required, min, max, defaultValue, helpText, metaValue, enumValues, conversionType, conversionType == typeof(int) && flagCounter ? TargetType.Switch : targetType, hidden)
{
this.ShortName = shortName;
this.LongName = longName;
this.Separator = separator;
this.SetName = setName;
this.Group = group;
this.FlagCounter = flagCounter;
}
public static OptionSpecification FromAttribute(OptionAttribute attribute, Type conversionType, IEnumerable<string> enumValues)
{
return new OptionSpecification(
attribute.ShortName,
attribute.LongName,
attribute.Required,
attribute.SetName,
attribute.Min == -1 ? Maybe.Nothing<int>() : Maybe.Just(attribute.Min),
attribute.Max == -1 ? Maybe.Nothing<int>() : Maybe.Just(attribute.Max),
attribute.Separator,
attribute.Default.ToMaybe(),
attribute.HelpText,
attribute.MetaValue,
enumValues,
conversionType,
conversionType.ToTargetType(),
attribute.Group,
attribute.FlagCounter,
attribute.Hidden);
}
public static OptionSpecification NewSwitch(string shortName, string longName, bool required, string helpText, string metaValue, bool hidden = false)
{
return new OptionSpecification(shortName, longName, required, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(),
'\0', Maybe.Nothing<object>(), helpText, metaValue, Enumerable.Empty<string>(), typeof(bool), TargetType.Switch, string.Empty, false, hidden);
}
public string ShortName { get; }
public string LongName { get; }
public char Separator { get; }
public string SetName { get; }
public string Group { get; }
/// <summary>
/// Whether this is an int option that counts how many times a flag was set rather than taking a value on the command line
/// </summary>
public bool FlagCounter { get; }
}
}