BadScript 2
Loading...
Searching...
No Matches
Verb.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;
6using System.Reflection;
7
8namespace CommandLine.Core
9{
10 internal sealed class Verb
11 {
12 public Verb(string name, string helpText, bool hidden, bool isDefault, string[] aliases)
13 {
14 if (string.IsNullOrWhiteSpace(name))
15 {
16 throw new ArgumentNullException(nameof(name));
17 }
18
19 Name = name;
20
21 HelpText = helpText ?? throw new ArgumentNullException(nameof(helpText));
22 Hidden = hidden;
23 IsDefault = isDefault;
24 Aliases = aliases ?? new string[0];
25 }
26
27 public string Name { get; private set; }
28
29 public string HelpText { get; private set; }
30
31 public bool Hidden { get; private set; }
32
33 public bool IsDefault { get; private set; }
34
35 public string[] Aliases { get; private set; }
36
37 public static Verb FromAttribute(VerbAttribute attribute)
38 {
39 return new Verb(attribute.Name,
40 attribute.HelpText,
41 attribute.Hidden,
42 attribute.IsDefault,
43 attribute.Aliases
44 );
45 }
46
47 public static IEnumerable<Tuple<Verb, Type>> SelectFromTypes(IEnumerable<Type> types)
48 {
49 return from type in types
50 let attrs = type.GetTypeInfo()
51 .GetCustomAttributes(typeof(VerbAttribute), true)
52 .ToArray()
53 where attrs.Length == 1
54 select Tuple.Create(FromAttribute((VerbAttribute)attrs.Single()),
55 type
56 );
57 }
58 }
59}
static Verb FromAttribute(VerbAttribute attribute)
Definition Verb.cs:37
Verb(string name, string helpText, bool hidden, bool isDefault, string[] aliases)
Definition Verb.cs:12
static IEnumerable< Tuple< Verb, Type > > SelectFromTypes(IEnumerable< Type > types)
Definition Verb.cs:47
string[] Aliases
Definition Verb.cs:35
Models a verb command specification.
string HelpText
Gets or sets a short description of this command line option. Usually a sentence summary.
bool Hidden
Gets or sets a value indicating whether a command line verb is visible in the help text.
string Name
Gets the verb name.
string[] Aliases
Gets or sets the aliases.
bool IsDefault
Gets whether this verb is the default verb.