BadScript 2
Loading...
Searching...
No Matches
Issue389Tests.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using Xunit;
5
7{
8 //Reference: PR# 392
9 public class Issue389Tests
10 {
11
12 private const int ERROR_SUCCESS = 0;
13
14 // Test method (xUnit) which fails
15 [Fact]
17 {
18 var result = Program.__Main(new[] { "--help" });
19
20 Assert.Equal(ERROR_SUCCESS, result);
21 }
22
23 // main program
24 internal class Program
25 {
26
27
28 internal static int __Main(string[] args)
29 {
30 bool hasError = false;
31 bool helpOrVersionRequested = false;
32
34 .WithNotParsed(errors => {
35 helpOrVersionRequested = errors.Any(
36 x => x.Tag == ErrorType.HelpRequestedError
37 || x.Tag == ErrorType.VersionRequestedError);
38 hasError = true;
39 });
40
41 if(helpOrVersionRequested)
42 {
43 return ERROR_SUCCESS;
44 }
45
46 // Execute as a normal call
47 // ...
48 return ERROR_SUCCESS;
49 }
50
51 }
52
53 // Options
54 internal class Options
55 {
56
57 [Option('c', "connectionString", Required = true, HelpText = "Texts.ExplainConnection")]
58 public string ConnectionString { get; set; }
59
60 [Option('j', "jobId", Required = true, HelpText = "Texts.ExplainJob")]
61 public int JobId { get; set; }
62
63 [Usage(ApplicationAlias = "Importer.exe")]
64 public static IEnumerable<Example> Examples
65 {
66 get => new[] {
67 new Example("Texts.ExplainExampleExecution", new Options() {
68 ConnectionString="Server=MyServer;Database=MyDatabase",
69 JobId = 5
70 }),
71 };
72 }
73
74 }
75 }
76}
Provides methods to parse command line arguments.
Definition Parser.cs:21
ParserResult< object > ParseArguments(IEnumerable< string > args, params Type[] types)
Parses a string array of command line arguments for verb commands scenario, constructing the proper i...
Definition Parser.cs:216
static Parser Default
Gets the singleton instance created with basic defaults.
Definition Parser.cs:75
Models a parser result. When inherited by CommandLine.Parsed<T>, it contains an instance of type T w...
static IEnumerable< Example > Examples
Models a command line usage example.
Definition Example.cs:13
ErrorType
Discriminator enumeration of CommandLine.Error derivates.
Definition Error.cs:13