Removed Humanizer.Core
SetMetadata not exclusive but with ConsoleKey.M GetParamCase
This commit is contained in:
parent
71baf499c7
commit
3c273da5f1
@ -9,7 +9,6 @@
|
|||||||
<UserSecretsId>eb9e8f58-fcb5-45bb-9d4d-54f064c485b1</UserSecretsId>
|
<UserSecretsId>eb9e8f58-fcb5-45bb-9d4d-54f064c485b1</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
|
||||||
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="7.0.9" />
|
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="7.0.9" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
using File_Folder_Helper.Models;
|
using File_Folder_Helper.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace File_Folder_Helper.Helpers;
|
namespace File_Folder_Helper.Helpers;
|
||||||
|
|
||||||
internal static class HelperKanbanMetadata
|
internal static partial class HelperKanbanMetadata
|
||||||
{
|
{
|
||||||
|
|
||||||
|
[GeneratedRegex("([A-Z]+(.))")]
|
||||||
|
private static partial Regex UpperCase();
|
||||||
|
|
||||||
|
[GeneratedRegex("[\\s!?.,@:;|\\\\/\"'`£$%\\^&*{}[\\]()<>~#+\\-=_¬]+")]
|
||||||
|
private static partial Regex InvalidCharacter();
|
||||||
|
|
||||||
private static List<(int, int, string, FileInfo)> GetCollectionFromIndex(string sourceDirectory, string[] lines)
|
private static List<(int, int, string, FileInfo)> GetCollectionFromIndex(string sourceDirectory, string[] lines)
|
||||||
{
|
{
|
||||||
List<(int, int, string, FileInfo)> results = new();
|
List<(int, int, string, FileInfo)> results = new();
|
||||||
@ -38,13 +46,66 @@ internal static class HelperKanbanMetadata
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetParamCase(string value)
|
||||||
|
{
|
||||||
|
string result;
|
||||||
|
StringBuilder stringBuilder = new(value);
|
||||||
|
Match[] matches = UpperCase().Matches(value).ToArray();
|
||||||
|
for (int i = matches.Length - 1; i > -1; i--)
|
||||||
|
_ = stringBuilder.Insert(matches[i].Index, '-');
|
||||||
|
string[] segments = InvalidCharacter().Split(stringBuilder.ToString().ToLower());
|
||||||
|
result = string.Join('-', segments).Trim('-');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TestParamCases()
|
||||||
|
{
|
||||||
|
if (GetParamCase("PascalCase") != "pascal-case")
|
||||||
|
throw new Exception("PascalCase");
|
||||||
|
if (GetParamCase("camelCase") != "camel-case")
|
||||||
|
throw new Exception("camelCase");
|
||||||
|
if (GetParamCase("snake_case") != "snake-case")
|
||||||
|
throw new Exception("snake_case");
|
||||||
|
if (GetParamCase("No Case") != "no-case")
|
||||||
|
throw new Exception("No Case");
|
||||||
|
if (GetParamCase("With 2 numbers 3") != "with-2-numbers-3")
|
||||||
|
throw new Exception("With 2 numbers 3");
|
||||||
|
if (GetParamCase("Multiple spaces") != "multiple-spaces")
|
||||||
|
throw new Exception("Multiple spaces");
|
||||||
|
if (GetParamCase("Tab\tCharacter") != "tab-character")
|
||||||
|
throw new Exception("Tab\tCharacter");
|
||||||
|
if (GetParamCase("New\nLine") != "new-line")
|
||||||
|
throw new Exception("New\nLine");
|
||||||
|
if (GetParamCase("Punctuation, Characters") != "punctuation-characters")
|
||||||
|
throw new Exception("Punctuation, Characters");
|
||||||
|
if (GetParamCase("M!o?r.e, @p:u;n|c\\t/u\"a\'t`i£o$n% ^c&h*a{r}a[c]t(e)r<s> ~l#i+k-e= _t¬hese") != "m-o-r-e-p-u-n-c-t-u-a-t-i-o-n-c-h-a-r-a-c-t-e-r-s-l-i-k-e-t-hese")
|
||||||
|
throw new Exception("M!o?r.e, @p:u;n|c\\t/u\"a\'t`i£o$n% ^c&h*a{r}a[c]t(e)r<s> ~l#i+k-e= _t¬hese");
|
||||||
|
if (GetParamCase("This string ends with punctuation!") != "this-string-ends-with-punctuation")
|
||||||
|
throw new Exception("This string ends with punctuation!");
|
||||||
|
if (GetParamCase("?This string starts with punctuation") != "this-string-starts-with-punctuation")
|
||||||
|
throw new Exception("?This string starts with punctuation");
|
||||||
|
if (GetParamCase("#This string has punctuation at both ends&") != "this-string-has-punctuation-at-both-ends")
|
||||||
|
throw new Exception("#This string has punctuation at both ends&");
|
||||||
|
if (GetParamCase("軟件 測試") != "軟件-測試")
|
||||||
|
throw new Exception("軟件 測試");
|
||||||
|
if (GetParamCase("実験 試し") != "実験-試し")
|
||||||
|
throw new Exception("実験 試し");
|
||||||
|
if (GetParamCase("יקספּערמענאַל פּרובירן") != "יקספּערמענאַל-פּרובירן")
|
||||||
|
throw new Exception("יקספּערמענאַל פּרובירן");
|
||||||
|
if (GetParamCase("я надеюсь, что это сработает") != "я-надеюсь-что-это-сработает")
|
||||||
|
throw new Exception("я надеюсь, что это сработает");
|
||||||
|
}
|
||||||
|
|
||||||
internal static void SetMetadata(ILogger log, AppSettings appSettings, string sourceDirectory)
|
internal static void SetMetadata(ILogger log, AppSettings appSettings, string sourceDirectory)
|
||||||
{
|
{
|
||||||
|
bool? match;
|
||||||
|
string? paramCase;
|
||||||
string statusLine;
|
string statusLine;
|
||||||
List<string> lines;
|
List<string> lines;
|
||||||
LineNumber lineNumber;
|
LineNumber lineNumber;
|
||||||
if (log is null)
|
if (log is null)
|
||||||
throw new NullReferenceException();
|
throw new NullReferenceException();
|
||||||
|
TestParamCases();
|
||||||
string fullPath = Path.GetFullPath(sourceDirectory);
|
string fullPath = Path.GetFullPath(sourceDirectory);
|
||||||
if (!Directory.Exists(fullPath))
|
if (!Directory.Exists(fullPath))
|
||||||
_ = Directory.CreateDirectory(fullPath);
|
_ = Directory.CreateDirectory(fullPath);
|
||||||
@ -61,14 +122,18 @@ internal static class HelperKanbanMetadata
|
|||||||
if (!lines.Any())
|
if (!lines.Any())
|
||||||
continue;
|
continue;
|
||||||
statusLine = $"status: \"{groupCount}-{group}\"";
|
statusLine = $"status: \"{groupCount}-{group}\"";
|
||||||
|
paramCase = lineNumber.H1 is null ? null : GetParamCase(lines[lineNumber.H1.Value]);
|
||||||
indexFileLines[itemLineNumber] = $"{fileInfo.LastWriteTime.Ticks}~~~{indexFileLines[itemLineNumber]}";
|
indexFileLines[itemLineNumber] = $"{fileInfo.LastWriteTime.Ticks}~~~{indexFileLines[itemLineNumber]}";
|
||||||
|
match = lineNumber.H1 is null || paramCase is null ? null : Path.GetFileNameWithoutExtension(fileInfo.Name) == paramCase;
|
||||||
if (lineNumber.FrontMatterYamlEnd is null)
|
if (lineNumber.FrontMatterYamlEnd is null)
|
||||||
throw new NotSupportedException($"{nameof(SetMetadata)} must be executed first!");
|
throw new NotSupportedException($"{nameof(SetMetadata)} must be executed first!");
|
||||||
|
if (lineNumber.H1 is not null && paramCase is not null && match is not null && !match.Value)
|
||||||
|
lines[lineNumber.H1.Value] = $"# {paramCase}";
|
||||||
if (lineNumber.Status is null)
|
if (lineNumber.Status is null)
|
||||||
lines.Insert(lineNumber.FrontMatterYamlEnd.Value, statusLine);
|
lines.Insert(lineNumber.FrontMatterYamlEnd.Value, statusLine);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (lines[lineNumber.Status.Value] == statusLine)
|
if ((match is null || match.Value) && lines[lineNumber.Status.Value] == statusLine)
|
||||||
continue;
|
continue;
|
||||||
lines[lineNumber.Status.Value] = statusLine;
|
lines[lineNumber.Status.Value] = statusLine;
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,6 @@ public class Worker : BackgroundService
|
|||||||
_Args.RemoveAt(singleCharIndex.Value);
|
_Args.RemoveAt(singleCharIndex.Value);
|
||||||
if (!_Args.Any())
|
if (!_Args.Any())
|
||||||
_Logger.LogInformation("Must pass a argument!");
|
_Logger.LogInformation("Must pass a argument!");
|
||||||
else if (_Args[0].EndsWith(".kanbn") && Directory.Exists(_Args[0]))
|
|
||||||
Helpers.HelperKanbanMetadata.SetMetadata(_Logger, _AppSettings, _Args[0]);
|
|
||||||
else if (Directory.Exists(_Args[0]) && File.Exists(Path.Combine(_Args[0], string.Concat(Path.GetFileName(_Args[0]), ".dll"))))
|
else if (Directory.Exists(_Args[0]) && File.Exists(Path.Combine(_Args[0], string.Concat(Path.GetFileName(_Args[0]), ".dll"))))
|
||||||
Helpers.HelperILMerge.ILMerge(_Args[0]);
|
Helpers.HelperILMerge.ILMerge(_Args[0]);
|
||||||
else if (Directory.Exists(_Args[0]))
|
else if (Directory.Exists(_Args[0]))
|
||||||
@ -138,6 +136,8 @@ public class Worker : BackgroundService
|
|||||||
Helpers.HelperCreateNoteFiles.CreateNoteFiles(_Args[0]);
|
Helpers.HelperCreateNoteFiles.CreateNoteFiles(_Args[0]);
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.M:
|
case ConsoleKey.M:
|
||||||
|
if (_Args[0].EndsWith(".kanbn") && Directory.Exists(_Args[0]))
|
||||||
|
Helpers.HelperKanbanMetadata.SetMetadata(_Logger, _AppSettings, _Args[0]);
|
||||||
Helpers.HelperMarkdown.MarkdownWikiLinkVerification(_AppSettings, _Logger, _Args);
|
Helpers.HelperMarkdown.MarkdownWikiLinkVerification(_AppSettings, _Logger, _Args);
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.R:
|
case ConsoleKey.R:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user