Skip to content

Commit 74fb4c5

Browse files
committed
Require readme to stay up to date with --help output
1 parent 6c12a9d commit 74fb4c5

File tree

4 files changed

+84
-16
lines changed

4 files changed

+84
-16
lines changed

Readme.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,29 @@ This tool is offered **as-is** for a notoriously complex problem. We hope (witho
3030

3131
```
3232
Usage:
33-
TFVCmigrator [options] <project-collection-url> <root-path>
33+
TfvcMigrator <project-collection-url> <root-path> [options]
3434
3535
Arguments:
36-
<project-collection-url> The URL of the Azure DevOps project collection.
37-
<root-path> The source path within the TFVC repository to migrate as a Git repository.
36+
<project-collection-url> The URL of the Azure DevOps project collection.
37+
<root-path> The source path within the TFVC repository to migrate as a Git repository.
3838
3939
Options:
40-
--authors <authors> (REQUIRED) Path to an authors file with lines mapping TFVC usernames to Git authors,
41-
e.g.: DOMAIN\John = John Doe <john@doe.com>
42-
--out-dir <out-dir> The directory path at which to create a new Git repository. Defaults to
43-
the last segment in the root path under the current directory.
44-
--min-changeset <min-changeset> The changeset defining the initial commit. Defaults to the first
45-
changeset under the given source path.
46-
--max-changeset <max-changeset> The last changeset to migrate. Defaults to the most recent changeset
47-
under the given source path.
48-
--root-path-changes <root-path-changes> Followed by one or more arguments with the format CS1234:$/New/Path.
49-
Changes the path that is mapped as the Git repository root to a new path
50-
during a specified changeset.
51-
--version Show version information
52-
-?, -h, --help Show help and usage information
40+
--authors <authors> (REQUIRED) Path to an authors file with lines mapping TFVC usernames to
41+
Git authors, e.g.: DOMAIN\John = John Doe <john@doe.com>
42+
--out-dir <out-dir> The directory path at which to create a new Git repository.
43+
Defaults to the last segment in the root path under the
44+
current directory.
45+
--min-changeset <min-changeset> The changeset defining the initial commit. Defaults to the
46+
first changeset under the given source path.
47+
--max-changeset <max-changeset> The last changeset to migrate. Defaults to the most recent
48+
changeset under the given source path.
49+
--root-path-changes <root-path-changes> Followed by one or more arguments with the format
50+
CS1234:$/New/Path. Changes the path that is mapped as the Git
51+
repository root to a new path during a specified changeset.
52+
--pat <pat> Optional PAT, required to access TFVC repositories hosted on
53+
Azure DevOps Services. If not provided Default Client
54+
Credentials will be used, these are only suitable for
55+
on-premise TFS/Azure DevOps Server.
56+
--version Show version information
57+
-?, -h, --help Show help and usage information
5358
```

TfvcMigrator.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
99
ProjectSection(SolutionItems) = preProject
1010
.editorconfig = .editorconfig
1111
src\Directory.Build.props = src\Directory.Build.props
12+
Readme.md = Readme.md
1213
EndProjectSection
1314
EndProject
1415
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TfvcMigrator.Tests", "src\TfvcMigrator.Tests\TfvcMigrator.Tests.csproj", "{2EA6C987-0EFC-4C95-8593-663730B40F18}"

src/TfvcMigrator.Tests/ReadmeTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Reflection;
2+
using System.Text.RegularExpressions;
3+
4+
namespace TfvcMigrator.Tests;
5+
6+
public static class ReadmeTests
7+
{
8+
[Test]
9+
public static void Command_line_arguments_section_is_up_to_date()
10+
{
11+
var helpOutput = TestUtils.CaptureConsoleOutput(() => Program.Main(new[] { "--help" }))
12+
.Replace(Assembly.GetEntryAssembly()!.GetName().Name!, typeof(Program).Assembly.GetName().Name);
13+
14+
var expectedReadmeCodeBlock = Regex.Replace(helpOutput, @"\ADescription:\s*\n[^\n]*\n\s*\n", "");
15+
16+
var readmeContents = File.ReadAllText(Path.Join(TestUtils.DetectSolutionDirectory(), "Readme.md"));
17+
var actualReadmeCodeBlock = Regex.Match(readmeContents, @"^## Command-line arguments(?:\s*\n)+```\s*\n(?<contents>.*)\s*\n```", RegexOptions.Singleline | RegexOptions.Multiline).Groups["contents"].Value;
18+
19+
if (Normalize(actualReadmeCodeBlock) != Normalize(expectedReadmeCodeBlock))
20+
{
21+
Assert.Fail("Update the ‘Command-line arguments’ section in Readme.md using the program output for the --help.");
22+
}
23+
}
24+
25+
private static string Normalize(string possiblyWrappedText)
26+
{
27+
return Regex.Replace(possiblyWrappedText.Trim(), @"\s+", " ");
28+
}
29+
}

src/TfvcMigrator.Tests/TestUtils.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace TfvcMigrator.Tests;
2+
3+
internal static class TestUtils
4+
{
5+
public static string CaptureConsoleOutput(Action action)
6+
{
7+
var writer = new StringWriter();
8+
9+
var originalConsoleOut = Console.Out;
10+
Console.SetOut(writer);
11+
try
12+
{
13+
action.Invoke();
14+
}
15+
finally
16+
{
17+
Console.SetOut(originalConsoleOut);
18+
}
19+
20+
return writer.ToString();
21+
}
22+
23+
public static string DetectSolutionDirectory()
24+
{
25+
for (var current = AppContext.BaseDirectory; current is not null; current = Path.GetDirectoryName(current))
26+
{
27+
if (Directory.EnumerateFiles(current, "*.sln").Any())
28+
return current;
29+
}
30+
31+
throw new InvalidOperationException("Unable to locate the solution directory.");
32+
}
33+
}

0 commit comments

Comments
 (0)