Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JKamsker committed Dec 25, 2024
1 parent 8cff772 commit 055a757
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<ItemGroup>
<PackageReference Include="Spectre.Verify.Extensions" Version="18.0.0" />

<PackageReference Include="Spectre.Console" Version="0.46.1-preview.0.19" />
<PackageReference Include="Spectre.Console.Cli" Version="0.46.1-preview.0.19" />
<PackageReference Include="Spectre.Console.Testing" Version="0.46.1-preview.0.19" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Testing" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
namespace JKToolKit.Spectre.AutoCompletion.Attributes;

//namespace StartTest.Attributes;
[AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = true)]
public sealed class CompletionSuggestionsAttribute : Attribute
{
public string[] Suggestions { get; }

//[System.AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = true)]
//internal sealed class CompletionSuggestionsAttribute : Attribute
//{
// public string[] Suggestions { get; }

// public CompletionSuggestionsAttribute(params string[] suggestions)
// {
// Suggestions = suggestions;
// }
//}
public CompletionSuggestionsAttribute(params string[] suggestions)
{
Suggestions = suggestions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Spectre.Console.Cli;

namespace JKToolKit.Spectre.AutoCompletion.Completion;

public class AutoCompletionConfiguration
{
public IConfigurator<CommandSettings> SpectreConfig { get; }

internal AutoCompletionConfiguration(IConfigurator<CommandSettings> spectreConfig)
{
SpectreConfig = spectreConfig;
}
}

This file was deleted.

5 changes: 3 additions & 2 deletions src/JKToolKit.Spectre.AutoCompletion/Completion/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ public static CommandParameterMatcher<TSettings> Match<TSettings>(this AsyncComm
return new CommandParameterMatcher<TSettings>();
}

public static IConfigurator AddAutoCompletion(this IConfigurator configurator, Action<IConfigurator<CommandSettings>>? action = null)
public static IConfigurator AddAutoCompletion(this IConfigurator configurator, Action<AutoCompletionConfiguration>? action = null)
{
configurator.AddBranch("completion", complete =>
{
complete.AddCommand<CompleteCommand>("complete").IsHidden();

if (action is not null)
{
action(complete);
var configuration = new AutoCompletionConfiguration(complete);
action(configuration);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text;
using JKToolKit.Spectre.AutoCompletion.Attributes;

namespace JKToolKit.Spectre.AutoCompletion.Completion.Internals;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using JKToolKit.Spectre.AutoCompletion.Helpers;
using JKToolKit.Spectre.AutoCompletion.Completion;
using JKToolKit.Spectre.AutoCompletion.Helpers;
using Spectre.Console.Cli;
using System.Runtime.InteropServices;
using System.Text;

namespace JKToolKit.Spectre.AutoCompletion.Integrations;
namespace JKToolKit.Spectre.AutoCompletion.Integrations.Powershell;

public static class Extensions
{
public static IConfigurator<CommandSettings> AddPowershell(
this IConfigurator<CommandSettings> settings,
public static AutoCompletionConfiguration AddPowershell(
this AutoCompletionConfiguration settings,
Action<PowershellIntegrationOptions>? configure = null
)
{
settings.AddDelegate<PowershellSettings>("powershell", (context, pwsh) =>
settings.SpectreConfig.AddDelegate<PowershellSettings>("powershell", (context, pwsh) =>
{
var options = new PowershellIntegrationOptions();
configure?.Invoke(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,42 +143,7 @@ public static string BuildIntegration(PowershellIntegrationBuilderSettings setti

return sb.ToString();
}

// removes everything after a comment in a line
// removes empty lines (whitespace also counts as empty)
// private static void Cleanup(StringBuilder sb)
// {
// for (int i = 0; i < sb.Length; i++)
// {
// if (sb[i] == '#')
// {
// var nextLineBreak = sb.IndexOf('\n', i);
// var length = nextLineBreak == -1
// ? sb.Length - i
// : nextLineBreak - i;
//
// sb.Remove(i, length);
// }
// }
//
// // Remove empty lines (whitespace also counts as empty)
// for (int i = 0; i < sb.Length; i++)
// {
// var indexOfLineBreak = sb.IndexOf('\n', i);
// if (indexOfLineBreak == -1)
// {
// break;
// }
//
// var isWhitespace = sb.IsWhiteSpace(i, indexOfLineBreak);
// if (isWhitespace)
// {
// sb.Remove(i, indexOfLineBreak - i);
// }
// }
// }



private static string GetResource(byte[] powershellIntegration_Install, Dictionary<string, string> replacements)
{
var result = Encoding.UTF8.GetString(powershellIntegration_Install);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<LangVersion>10.0</LangVersion>
<PlatformTarget>AnyCPU</PlatformTarget>

<Version>0.0.8</Version>
<Version>0.0.9</Version>
<PackageReleaseNotes>
Fixing potential encoding issues
</PackageReleaseNotes>
Expand Down
1 change: 1 addition & 0 deletions src/samples/AutoCompletionExample/Commands/LionCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using JKToolKit.Spectre.AutoCompletion.Attributes;
using JKToolKit.Spectre.AutoCompletion.Completion;
using Spectre.Console.Cli;

Expand Down
1 change: 1 addition & 0 deletions src/samples/AutoCompletionExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Spectre.Console.Cli;
using System.Diagnostics;
using JKToolKit.Spectre.AutoCompletion.Integrations;
using JKToolKit.Spectre.AutoCompletion.Integrations.Powershell;

namespace AutoCompletionExample;

Expand Down

0 comments on commit 055a757

Please sign in to comment.