BadScript 2
Loading...
Searching...
No Matches
HelpTextExtensions.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.IO;
6using System.Linq;
7
8namespace CommandLine
9{
10 public static class HelpTextExtensions
11 {
15 public static bool IsHelp(this IEnumerable<Error> errs)
16 {
17 if (errs.Any(x => x.Tag == ErrorType.HelpRequestedError ||
18 x.Tag == ErrorType.HelpVerbRequestedError
19 ))
20 {
21 return true;
22 }
23
24 //when AutoHelp=false in parser, help is disabled and Parser raise UnknownOptionError
25 return errs.Any(x => (x is UnknownOptionError ee ? ee.Token : "") == "help");
26 }
27
31 public static bool IsVersion(this IEnumerable<Error> errs)
32 {
33 if (errs.Any(x => x.Tag == ErrorType.VersionRequestedError))
34 {
35 return true;
36 }
37
38 //when AutoVersion=false in parser, Version is disabled and Parser raise UnknownOptionError
39 return errs.Any(x => (x is UnknownOptionError ee ? ee.Token : "") == "version");
40 }
41
45 public static TextWriter Output(this IEnumerable<Error> errs)
46 {
47 if (errs.IsHelp() || errs.IsVersion())
48 {
49 return Console.Out;
50 }
51
52 return Console.Error;
53 }
54 }
55}
static TextWriter Output(this IEnumerable< Error > errs)
redirect errs to Console.Error, and to Console.Out for help/version error
static bool IsVersion(this IEnumerable< Error > errs)
return true when errors contain VersionXXXError
static bool IsHelp(this IEnumerable< Error > errs)
return true when errors contain HelpXXXError
string Token
The string containing the token text.
Definition Error.cs:222
Models an error generated when an unknown option is detected.
Definition Error.cs:383
ErrorType
Discriminator enumeration of CommandLine.Error derivates.
Definition Error.cs:13