-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* VCI-102: Add help command * VCI-102: Fix codesmells * VCI-102: Make HelpProvider static * VCI-129: Make help search case insensitive
- Loading branch information
1 parent
75af6eb
commit 72d9ac3
Showing
8 changed files
with
1,329 additions
and
1,286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
using System.ComponentModel; | ||
using Nuke.Common.Tooling; | ||
|
||
[TypeConverter(typeof(TypeConverter<Configuration>))] | ||
public class Configuration : Enumeration | ||
namespace VirtoCommerce.Build | ||
{ | ||
public readonly static Configuration Debug = new Configuration { Value = nameof(Debug) }; | ||
public readonly static Configuration Release = new Configuration { Value = nameof(Release) }; | ||
|
||
public static implicit operator string(Configuration configuration) | ||
[TypeConverter(typeof(TypeConverter<Configuration>))] | ||
public class Configuration : Enumeration | ||
{ | ||
return configuration.Value; | ||
public readonly static Configuration Debug = new Configuration { Value = nameof(Debug) }; | ||
public readonly static Configuration Release = new Configuration { Value = nameof(Release) }; | ||
|
||
public static implicit operator string(Configuration configuration) | ||
{ | ||
return configuration.Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
using Nuke.Common; | ||
|
||
internal partial class Build | ||
namespace VirtoCommerce.Build | ||
{ | ||
[Parameter("Grab-migrator config file")] | ||
public static string GrabMigratorConfig { get; set; } | ||
internal partial class Build | ||
{ | ||
[Parameter("Grab-migrator config file")] | ||
public static string GrabMigratorConfig { get; set; } | ||
|
||
public Target GrabMigrator => _ => _ | ||
.Requires(() => GrabMigratorConfig) | ||
.Executes(() => | ||
{ | ||
new GrabMigrator.GrabMigrator().Do(GrabMigratorConfig); | ||
}); | ||
public Target GrabMigrator => _ => _ | ||
.Requires(() => GrabMigratorConfig) | ||
.Executes(() => | ||
{ | ||
new GrabMigrator.GrabMigrator().Do(GrabMigratorConfig); | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using Markdig; | ||
using Markdig.Extensions.CustomContainers; | ||
using Markdig.Helpers; | ||
using Markdig.Syntax; | ||
using Markdig.Syntax.Inlines; | ||
using Nuke.Common; | ||
|
||
namespace VirtoCommerce.Build.HelpProvider | ||
{ | ||
public static class HelpProvider | ||
{ | ||
public static string GetHelpForTarget(string target) | ||
{ | ||
var containers = GetCustomContainers(); | ||
|
||
var container = containers.FirstOrDefault(c => | ||
{ | ||
var heading = c.Descendants<HeadingBlock>().FirstOrDefault(); | ||
|
||
if (heading == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return string.Compare(target, GetTextContent(heading), true) == 0; | ||
}); | ||
|
||
if (container == null) | ||
{ | ||
Logger.Error($"Help is not found for the target {target}"); | ||
return string.Empty; | ||
} | ||
|
||
var descriptionBlock = container.Descendants<ParagraphBlock>().FirstOrDefault(); | ||
var exampleBlock = container.Descendants<FencedCodeBlock>().FirstOrDefault(); | ||
var description = GetTextContent(descriptionBlock); | ||
var examples = GetFencedText(exampleBlock); | ||
var result = $"{description}{Environment.NewLine}{examples}"; | ||
return result; | ||
} | ||
|
||
public static IEnumerable<string> GetTargets() | ||
{ | ||
var containers = GetCustomContainers(); | ||
var result = new List<string>(); | ||
foreach (var container in containers) | ||
{ | ||
var heading = container.Descendants<HeadingBlock>().FirstOrDefault(); | ||
|
||
if (heading == null) | ||
{ | ||
continue; | ||
} | ||
result.Add(GetTextContent(heading)); | ||
} | ||
return result; | ||
} | ||
|
||
private static IEnumerable<CustomContainer> GetCustomContainers() | ||
{ | ||
var pipeline = new MarkdownPipelineBuilder().UseCustomContainers().Build(); | ||
var rootDirectory = AppDomain.CurrentDomain.BaseDirectory; | ||
var helpFilePath = Path.Combine(rootDirectory, "docs", "targets.md"); | ||
var markdownDocument = Markdown.Parse(File.ReadAllText(helpFilePath), pipeline); | ||
return markdownDocument.Descendants<CustomContainer>(); | ||
} | ||
|
||
private static string GetTextContent(LeafBlock leaf) | ||
{ | ||
var inline = leaf?.Inline?.FirstChild; | ||
|
||
if (inline is null) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
var result = new StringBuilder(); | ||
|
||
do | ||
{ | ||
switch (inline) | ||
{ | ||
case LiteralInline literal: | ||
var inlineContent = literal.Content; | ||
result.Append(inlineContent.Text.Substring(inlineContent.Start, inlineContent.Length)); | ||
break; | ||
|
||
case LineBreakInline: | ||
result.Append(Environment.NewLine); | ||
break; | ||
} | ||
|
||
inline = inline.NextSibling; | ||
} | ||
while (inline != null); | ||
|
||
return result.ToString(); | ||
} | ||
|
||
private static string GetFencedText(FencedCodeBlock fencedCodeBlock) | ||
{ | ||
if (fencedCodeBlock == null) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
var lines = fencedCodeBlock.Lines.Lines.Select(line => | ||
{ | ||
var slice = line.Slice; | ||
|
||
if (EqualityComparer<StringSlice>.Default.Equals(slice, default)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
return slice.Text?.Substring(line.Slice.Start, line.Slice.Length) ?? string.Empty; | ||
}); | ||
|
||
return string.Join(Environment.NewLine, lines); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.