Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Aug 31, 2024
2 parents 3000fed + 3b6a3bb commit 399c5b3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 30 deletions.
32 changes: 16 additions & 16 deletions src/ConfigReader/ConfigResult.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
public class ConfigResult
{
public bool? ReadOnly;
public bool ValidateContent;
public bool OmitSnippetLinks;
public LinkFormat LinkFormat;
public DocumentConvention Convention;
public int TocLevel;
public int MaxWidth;
public List<string> UrlsAsSnippets = [];
public List<string> ExcludeDirectories = [];
public List<string> ExcludeMarkdownDirectories = [];
public List<string> ExcludeSnippetDirectories = [];
public bool? WriteHeader;
public string? Header;
public string? UrlPrefix;
public List<string> TocExcludes = [];
public bool TreatMissingAsWarning;
public bool? ReadOnly { get; init; }
public bool ValidateContent { get; init; }
public bool OmitSnippetLinks { get; init; }
public LinkFormat LinkFormat { get; init; }
public DocumentConvention Convention { get; init; }
public int TocLevel { get; init; }
public int MaxWidth { get; init; }
public List<string>? UrlsAsSnippets { get; init; }
public List<string>? ExcludeDirectories { get; init; }
public List<string>? ExcludeMarkdownDirectories { get; init; }
public List<string>? ExcludeSnippetDirectories { get; init; }
public bool? WriteHeader { get; init; }
public string? Header { get; init; }
public string? UrlPrefix { get; init; }
public List<string>? TocExcludes { get; init; }
public bool TreatMissingAsWarning { get; init; }
}
8 changes: 7 additions & 1 deletion src/ConfigReader/ExcludeToFilterBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
static class ExcludeToFilterBuilder
{
public static ShouldIncludeDirectory ExcludesToFilter(List<string> excludes) =>
public static ShouldIncludeDirectory ExcludesToFilter(List<string>? excludes) =>
path =>
{
if (DefaultDirectoryExclusions.ShouldExcludeDirectory(path))
{
return false;
}

if(excludes == null ||
excludes.Count == 0)
{
return false;
}

if (!excludes.Any(path.Contains))
{
return true;
Expand Down
25 changes: 15 additions & 10 deletions src/ConfigReader/LogBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,53 +37,58 @@ public static string BuildConfigLogMessage(string targetDirectory, ConfigResult
$" MaxWidth: {maxWidth}");
}

if (config.ExcludeDirectories.Count != 0)
var excludeDirectories = config.ExcludeDirectories;
if (excludeDirectories != null && excludeDirectories.Count != 0)
{
Polyfill.AppendLine(
builder,
$"""
ExcludeDirectories:
{string.Join("\r\n ", config.ExcludeDirectories)}
{string.Join("\r\n ", excludeDirectories)}
""");
}

if (config.ExcludeMarkdownDirectories.Count != 0)
var excludeMarkdownDirectories = config.ExcludeMarkdownDirectories;
if (excludeMarkdownDirectories != null && excludeMarkdownDirectories.Count != 0)
{
Polyfill.AppendLine(
builder,
$"""
ExcludeMarkdownDirectories:
{string.Join("\r\n ", config.ExcludeMarkdownDirectories)}
{string.Join("\r\n ", excludeMarkdownDirectories)}
""");
}

if (config.ExcludeSnippetDirectories.Count != 0)
var excludeSnippetDirectories = config.ExcludeSnippetDirectories;
if (excludeSnippetDirectories != null && excludeSnippetDirectories.Count != 0)
{
Polyfill.AppendLine(
builder,
$"""
ExcludeSnippetDirectories:
{string.Join("\r\n ", config.ExcludeSnippetDirectories)}
{string.Join("\r\n ", excludeSnippetDirectories)}
""");
}

if (config.TocExcludes.Count != 0)
var tocExcludes = config.TocExcludes;
if (tocExcludes != null && tocExcludes.Count != 0)
{
Polyfill.AppendLine(
builder,
$"""
TocExcludes:
{string.Join("\r\n ", config.TocExcludes)}
{string.Join("\r\n ", tocExcludes)}
""");
}

if (config.UrlsAsSnippets.Count != 0)
var urlsAsSnippets = config.UrlsAsSnippets;
if (urlsAsSnippets != null && urlsAsSnippets.Count != 0)
{
Polyfill.AppendLine(
builder,
$"""
UrlsAsSnippets:
{string.Join("\r\n ", config.UrlsAsSnippets)}
{string.Join("\r\n ", urlsAsSnippets)}
""");
}

Expand Down
7 changes: 6 additions & 1 deletion src/MarkdownSnippets.MsBuild/DocoTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public override bool Execute()
try
{
var snippets = new List<Snippet>();
snippets.AppendUrlsAsSnippets(configResult.UrlsAsSnippets).GetAwaiter().GetResult();
var urlsAsSnippets = configResult.UrlsAsSnippets;
if (urlsAsSnippets != null)
{
snippets.AppendUrlsAsSnippets(urlsAsSnippets).GetAwaiter().GetResult();
}

processor.AddSnippets(snippets);
var snippetsInError = processor.Snippets.Where(_ => _.IsInError).ToList();
if (snippetsInError.Any())
Expand Down
5 changes: 3 additions & 2 deletions src/MarkdownSnippets.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ static async Task Inner(string targetDirectory, ConfigInput configInput)
validateContent: configResult.ValidateContent,
omitSnippetLinks: configResult.OmitSnippetLinks);

if (configResult.UrlsAsSnippets.Count != 0)
var urlsAsSnippets = configResult.UrlsAsSnippets;
if (urlsAsSnippets != null && urlsAsSnippets.Count != 0)
{
var snippets = new List<Snippet>();

await snippets.AppendUrlsAsSnippets(configResult.UrlsAsSnippets);
await snippets.AppendUrlsAsSnippets(urlsAsSnippets);
processor.AddSnippets(snippets);
}

Expand Down

0 comments on commit 399c5b3

Please sign in to comment.