BadScript 2
Loading...
Searching...
No Matches
Issue389Tests.cs
Go to the documentation of this file.
1
using
System.Collections.Generic;
2
using
System.Linq;
3
using
Xunit;
4
using
CommandLine.Text
;
5
6
namespace
CommandLine.Tests.Unit
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]
16
public
void
CallMain_GiveHelpArgument_ExpectSuccess
()
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
33
ParserResult<Options>
parsedOptions =
Parser
.
Default
.
ParseArguments
<
Options
>(args)
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
}
CommandLine.Parser
Provides methods to parse command line arguments.
Definition
Parser.cs:21
CommandLine.Parser.ParseArguments
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
CommandLine.Parser.Default
static Parser Default
Gets the singleton instance created with basic defaults.
Definition
Parser.cs:75
CommandLine.ParserResult
Models a parser result. When inherited by CommandLine.Parsed<T>, it contains an instance of type T w...
Definition
ParserResult.cs:57
CommandLine.Tests.Unit.Issue389Tests.Options
Definition
Issue389Tests.cs:55
CommandLine.Tests.Unit.Issue389Tests.Options.Examples
static IEnumerable< Example > Examples
Definition
Issue389Tests.cs:65
CommandLine.Tests.Unit.Issue389Tests.Options.JobId
int JobId
Definition
Issue389Tests.cs:61
CommandLine.Tests.Unit.Issue389Tests.Options.ConnectionString
string ConnectionString
Definition
Issue389Tests.cs:58
CommandLine.Tests.Unit.Issue389Tests.Program
Definition
Issue389Tests.cs:25
CommandLine.Tests.Unit.Issue389Tests.Program.__Main
static int __Main(string[] args)
Definition
Issue389Tests.cs:28
CommandLine.Tests.Unit.Issue389Tests
Definition
Issue389Tests.cs:10
CommandLine.Tests.Unit.Issue389Tests.ERROR_SUCCESS
const int ERROR_SUCCESS
Definition
Issue389Tests.cs:12
CommandLine.Tests.Unit.Issue389Tests.CallMain_GiveHelpArgument_ExpectSuccess
void CallMain_GiveHelpArgument_ExpectSuccess()
Definition
Issue389Tests.cs:16
CommandLine.Text.Example
Models a command line usage example.
Definition
Example.cs:13
CommandLine.Text.HelpText
Definition
HelpText.cs:33
CommandLine.Tests.Unit
Definition
BaseAttributeTests.cs:5
CommandLine.Text
Definition
AssemblyLicenseAttribute.cs:7
CommandLine.ErrorType
ErrorType
Discriminator enumeration of CommandLine.Error derivates.
Definition
Error.cs:13
deps
commandlineparser
tests
CommandLine.Tests
Unit
Issue389Tests.cs
Generated by
1.9.8