Skip to content

Commit 6f5dbee

Browse files
committed
Make command parameters required
1 parent 23786d0 commit 6f5dbee

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

GitHubIssueFormsParser/src/GitHubIssuesParserCli/CliCommands/ParseIssueFormCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ namespace GitHubIssuesParserCli.CliCommands;
33
[Command("parse-issue-form")]
44
public class ParseIssueFormCommand : ICommand
55
{
6-
[CommandOption("issue-body", 'i', Description = "The body of the GitHub issue form.")]
7-
public string? IssueFormBody { get; init; }
6+
[CommandOption("issue-body", 'i', IsRequired = true, Description = "The body of the GitHub issue form.")]
7+
public string IssueFormBody { get; init; } = default!;
88

9-
[CommandOption("template-filepath", 't', Description = "The filepath for the GitHub issue form YAML template.")]
10-
public string? TemplateFilepath { get; init; }
9+
[CommandOption("template-filepath", 't', IsRequired = true, Description = "The filepath for the GitHub issue form YAML template.")]
10+
public string TemplateFilepath { get; init; } = default!;
1111

1212
public async ValueTask ExecuteAsync(IConsole console)
1313
{

GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/NormalizedLineEndingsFileReader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static string ReadAllText(string path)
1515
// if it's a Windows OS and contains Windows line endings then do nothing
1616
return original;
1717
}
18+
1819
if (Environment.OSVersion.Platform == PlatformID.Win32NT && original.Contains(LF, StringComparison.Ordinal))
1920
{
2021
// if it's a Windows OS and doesn't contain Windows line endings then replace

GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandValidationTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class ParseIssueFormCommandValidationTests
99
[Theory]
1010
[InlineData(null)]
1111
[InlineData("")]
12-
public async Task ValidateIssueFormBodyParam(string? issueFormBody)
12+
[InlineData(" ")]
13+
public async Task ValidateIssueFormBodyParam(string issueFormBody)
1314
{
1415
using var console = new FakeInMemoryConsole();
1516
var command = new ParseIssueFormCommand
@@ -30,7 +31,8 @@ public async Task ValidateIssueFormBodyParam(string? issueFormBody)
3031
[Theory]
3132
[InlineData(null)]
3233
[InlineData("")]
33-
public async Task ValidateTemplateFilepathParam(string? templateFilepath)
34+
[InlineData(" ")]
35+
public async Task ValidateTemplateFilepathParam(string templateFilepath)
3436
{
3537
using var console = new FakeInMemoryConsole();
3638
var command = new ParseIssueFormCommand

GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliIntegration/CliIntegrationTests.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CliIntegrationTests
1111
/// Tests that if no arguments are passed the CLI returns the help text.
1212
/// </summary>
1313
[Fact]
14-
public async Task IntegrationTest1()
14+
public async Task NoArguments()
1515
{
1616
using var console = new FakeInMemoryConsole();
1717
var app = new IssuesParserCli();
@@ -22,13 +22,47 @@ public async Task IntegrationTest1()
2222
output.ShouldEndWith(expectedOutput);
2323
}
2424

25+
/// <summary>
26+
/// Tests that the --issue-body parameter is required for the 'parse-issue-form' command.
27+
/// </summary>
28+
[Fact]
29+
public async Task IssueBodyParamIsRequired()
30+
{
31+
using var console = new FakeInMemoryConsole();
32+
var app = new IssuesParserCli();
33+
app.CliApplicationBuilder.UseConsole(console);
34+
35+
var args = new[] { "parse-issue-form", "--template-filepath", "some filepath" };
36+
await app.RunAsync(args);
37+
var output = console.ReadOutputString();
38+
var expectedOutput = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/CliOutputRequiredParam.txt");
39+
output.ShouldEndWith(expectedOutput);
40+
}
41+
42+
/// <summary>
43+
/// Tests that the --template-filepath parameter is required for the 'parse-issue-form' command.
44+
/// </summary>
45+
[Fact]
46+
public async Task TemplateFilepathParamIsRequired()
47+
{
48+
using var console = new FakeInMemoryConsole();
49+
var app = new IssuesParserCli();
50+
app.CliApplicationBuilder.UseConsole(console);
51+
52+
var args = new[] { "parse-issue-form", "--issue-body", "some issue body" };
53+
await app.RunAsync(args);
54+
var output = console.ReadOutputString();
55+
var expectedOutput = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/CliOutputRequiredParam.txt");
56+
output.ShouldEndWith(expectedOutput);
57+
}
58+
2559
/// <summary>
2660
/// Tests the correct value for the options that can be used with the 'parse-issue-form' command.
2761
/// </summary>
2862
[Theory]
2963
[InlineData("-i", "-t")]
3064
[InlineData("--issue-body", "--template-filepath")]
31-
public async Task IntegrationTest2(string issueFormParamName, string templateFilepathParamName)
65+
public async Task ExpectedUsage(string issueFormParamName, string templateFilepathParamName)
3266
{
3367
using var console = new FakeInMemoryConsole();
3468
var app = new IssuesParserCli();

GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/GitHubIssuesParserCli.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
</ItemGroup>
2525

2626
<ItemGroup>
27+
<None Update="TestFiles\CliOutputRequiredParam.txt">
28+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29+
</None>
2730
<None Update="TestFiles\CliOutputNoArgs.txt">
2831
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2932
</None>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
USAGE
2+
testhost parse-issue-form --issue-body <value> --template-filepath <value> [options]
3+
4+
OPTIONS
5+
* -i|--issue-body The body of the GitHub issue form.
6+
* -t|--template-filepath The filepath for the GitHub issue form YAML template.
7+
-h|--help Shows help text.

0 commit comments

Comments
 (0)