BadScript 2
Loading...
Searching...
No Matches
PreprocessorGuards.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
7namespace CommandLine.Core
8{
9 internal static class PreprocessorGuards
10 {
11 public static IEnumerable<Func<IEnumerable<string>, IEnumerable<Error>>>
12 Lookup(StringComparer nameComparer, bool autoHelp, bool autoVersion)
13 {
14 List<Func<IEnumerable<string>, IEnumerable<Error>>> list =
15 new List<Func<IEnumerable<string>, IEnumerable<Error>>>();
16
17 if (autoHelp)
18 {
19 list.Add(HelpCommand(nameComparer));
20 }
21
22 if (autoVersion)
23 {
24 list.Add(VersionCommand(nameComparer));
25 }
26
27 return list;
28 }
29
30 public static Func<IEnumerable<string>, IEnumerable<Error>> HelpCommand(StringComparer nameComparer)
31 {
32 return
33 arguments =>
34 nameComparer.Equals("--help", arguments.First())
35 ? new Error[] { new HelpRequestedError() }
36 : Enumerable.Empty<Error>();
37 }
38
39 public static Func<IEnumerable<string>, IEnumerable<Error>> VersionCommand(StringComparer nameComparer)
40 {
41 return
42 arguments =>
43 nameComparer.Equals("--version", arguments.First())
44 ? new Error[] { new VersionRequestedError() }
45 : Enumerable.Empty<Error>();
46 }
47 }
48}
static IEnumerable< Func< IEnumerable< string >, IEnumerable< Error > > > Lookup(StringComparer nameComparer, bool autoHelp, bool autoVersion)
static Func< IEnumerable< string >, IEnumerable< Error > > VersionCommand(StringComparer nameComparer)
static Func< IEnumerable< string >, IEnumerable< Error > > HelpCommand(StringComparer nameComparer)
Base type of all errors.
Definition Error.cs:110
Models an error generated when a user explicitly requests help.
Definition Error.cs:454
Models an error generated when a user explicitly requests version.
Definition Error.cs:504