Skip to content

Commit

Permalink
Update to preview 7 (#181)
Browse files Browse the repository at this point in the history
Also adds settings commands and sub commands, with option to show / hide the local, and option to disable / enable the newly added version check which will check nuget for latest package version between command runs every run and notify you of an update.
  • Loading branch information
prom3theu5 authored May 7, 2024
1 parent 53d6bdc commit ddf340a
Show file tree
Hide file tree
Showing 17 changed files with 378 additions and 20 deletions.
9 changes: 5 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@
<PackageVersion Include="DockerComposeBuilder" Version="0.2.4" />
<PackageVersion Include="Handlebars.Net" Version="2.1.6" />
<PackageVersion Include="JsonPath.Net" Version="1.0.1.2" />
<PackageVersion Include="KubernetesClient" Version="13.0.26" />
<PackageVersion Include="KubernetesClient" Version="13.0.37" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="NuGet.Protocol" Version="6.9.1" />
<PackageVersion Include="Spectre.Console" Version="0.48.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="YamlDotNet" Version="15.1.2" />
<PackageVersion Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="21.0.2" />
<PackageVersion Include="TestableIO.System.IO.Abstractions.Wrappers" Version="21.0.2" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="Spectre.Console.Testing" Version="0.48.0" />
<PackageVersion Include="Spectre.Console.Testing" Version="0.49.1" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Verify.Xunit" Version="24.1.0" />
<PackageVersion Include="xunit" Version="2.7.1" />
<PackageVersion Include="xunit" Version="2.8.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.8">
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
Expand Down
26 changes: 23 additions & 3 deletions src/Aspirate.Cli/AspirateCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ internal class AspirateCli : RootCommand
{
internal static void WelcomeMessage()
{
var skipLogo = Environment.GetEnvironmentVariable("ASPIRATE_NO_LOGO");

if (!string.IsNullOrEmpty(skipLogo))
if (ShouldSkipLogo())
{
return;
}
Expand All @@ -17,12 +15,34 @@ internal static void WelcomeMessage()
AnsiConsole.WriteLine();
}

private static bool ShouldSkipLogo()
{
var appDataFolder = GetAppDataFolder();
var skipLogoFile = Path.Combine(appDataFolder, AspirateLiterals.LogoDisabledFile);
var skipLogo = Environment.GetEnvironmentVariable("ASPIRATE_NO_LOGO");

return !string.IsNullOrEmpty(skipLogo) || File.Exists(skipLogoFile);
}

private static string GetAppDataFolder()
{
var appDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AspirateLiterals.AppDataFolder);

if (!Directory.Exists(appDataFolder))
{
Directory.CreateDirectory(appDataFolder);
}

return appDataFolder;
}

public AspirateCli()
{
AddCommand(new InitCommand());
AddCommand(new GenerateCommand());
AddCommand(new BuildCommand());
AddCommand(new ApplyCommand());
AddCommand(new DestroyCommand());
AddCommand(new SettingsCommand());
}
}
3 changes: 3 additions & 0 deletions src/Aspirate.Cli/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
global using System.CommandLine;
global using System.CommandLine.Builder;
global using System.CommandLine.Invocation;
global using System.CommandLine.NamingConventionBinder;
global using System.CommandLine.Parsing;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.DependencyInjection.Extensions;
Expand All @@ -15,7 +16,9 @@
global using Aspirate.Commands.Commands.Destroy;
global using Aspirate.Commands.Commands.Generate;
global using Aspirate.Commands.Commands.Init;
global using Aspirate.Commands.Commands.Settings;
global using Aspirate.Processors;
global using Aspirate.Secrets;
global using Aspirate.Services;
global using Aspirate.Shared.Literals;
global using Spectre.Console;
3 changes: 3 additions & 0 deletions src/Aspirate.Commands/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ private async Task<int> ConstructCommand(TOptions options, IServiceCollection se

var stateService = handler.Services.GetRequiredService<IStateService>();
var secretService = handler.Services.GetRequiredService<ISecretService>();
var versionCheckService = handler.Services.GetRequiredService<IVersionCheckService>();

await versionCheckService.CheckVersion();

var stateOptions = GetStateManagementOptions(options, handler);

Expand Down
2 changes: 0 additions & 2 deletions src/Aspirate.Commands/Commands/BaseCommandOptionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ protected BaseCommandOptionsHandler(IServiceProvider serviceProvider)

public AspirateState CurrentState { get; set; }
public IServiceProvider Services { get; }

protected ActionExecutor ActionExecutor { get; set; }

public abstract Task<int> HandleAsync(TOptions options);
}
19 changes: 19 additions & 0 deletions src/Aspirate.Commands/Commands/GenericCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Aspirate.Commands.Commands;

[ExcludeFromCodeCoverage]
public class GenericCommand : Command
{
public GenericCommand(string name, string description)
: base(name, description) =>
Handler = CommandHandler.Create<IServiceCollection>(ExecuteCommand);

protected virtual Task<int> ExecuteCommand(IServiceCollection services) => Task.FromResult(0);

protected static Table CreateHelpTable()
{
var table = new Table();
table.AddColumn("Sub Commands");
table.AddColumn("Description");
return table;
}
}
121 changes: 121 additions & 0 deletions src/Aspirate.Commands/Commands/Settings/SettingsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
namespace Aspirate.Commands.Commands.Settings;

public sealed class SettingsCommand : GenericCommand
{
public SettingsCommand() : base("settings", "Managed Aspir8 settings.")
{
AddCommand(new UpdateChecksCommand());
AddCommand(new LogoCommand());
}

protected override Task<int> ExecuteCommand(IServiceCollection services)
{
var table = CreateHelpTable();

table.AddRow("update-checks", "Enable / Disable Aspir8 version update checks.");
table.AddRow("logo", "Show / Hide the Aspir8 logo.");

AnsiConsole.Render(table);
return Task.FromResult(0);
}
}

internal sealed class LogoCommand : GenericCommand
{
public LogoCommand() : base("logo", "Show / Hide the Aspir8 logo.")
{
AddCommand(new ShowLogoCommand());
AddCommand(new HideLogoCommand());
}

protected override Task<int> ExecuteCommand(IServiceCollection services)
{
var table = CreateHelpTable();

table.AddRow("show", "Show the Aspir8 logo.");
table.AddRow("hide", "Hide the Aspir8 logo.");

AnsiConsole.Render(table);
return Task.FromResult(0);
}
}

internal sealed class UpdateChecksCommand : GenericCommand
{
public UpdateChecksCommand() : base("update-checks", "Manage Aspirate Version Checks.")
{
AddCommand(new EnableUpdateChecksCommand());
AddCommand(new DisableUpdateChecksCommand());
}

protected override Task<int> ExecuteCommand(IServiceCollection services)
{
var table = CreateHelpTable();

table.AddRow("enable", "Enables Aspir8 version checks.");
table.AddRow("disable", "Disables Aspir8 version checks.");

AnsiConsole.Render(table);
return Task.FromResult(0);
}
}

internal sealed class EnableUpdateChecksCommand() : GenericCommand("enable", "Enables Aspir8 version checks.")
{
protected override async Task<int> ExecuteCommand(IServiceCollection services)
{
var serviceProvider = services.BuildServiceProvider();
var versionCheckService = serviceProvider.GetRequiredService<IVersionCheckService>();
await versionCheckService.SetUpdateChecks(true);
return 0;
}
}

internal sealed class DisableUpdateChecksCommand() : GenericCommand("disable", "Disables Aspir8 version checks.")
{
protected override async Task<int> ExecuteCommand(IServiceCollection services)
{
var serviceProvider = services.BuildServiceProvider();
var versionCheckService = serviceProvider.GetRequiredService<IVersionCheckService>();
await versionCheckService.SetUpdateChecks(false);
return 0;
}
}

internal sealed class ShowLogoCommand() : GenericCommand("show", "Show the aspirate Logo.")
{
protected override Task<int> ExecuteCommand(IServiceCollection services)
{
var serviceProvider = services.BuildServiceProvider();
var fileSystem = serviceProvider.GetRequiredService<IFileSystem>();
var logger = serviceProvider.GetRequiredService<IAnsiConsole>();
var appDataFolder = fileSystem.AspirateAppDataFolder();
var logoFilePath = fileSystem.Path.Combine(appDataFolder, AspirateLiterals.LogoDisabledFile);

if (fileSystem.File.Exists(logoFilePath))
{
fileSystem.File.Delete(logoFilePath);
logger.MarkupLine($"[green]({EmojiLiterals.CheckMark}) Done:[/] The Aspir8 logo will now be [blue]shown[/].");

}

return Task.FromResult(0);
}
}

internal sealed class HideLogoCommand() : GenericCommand("hide", "Hide the Aspir8 logo.")
{
protected override async Task<int> ExecuteCommand(IServiceCollection services)
{
var serviceProvider = services.BuildServiceProvider();
var fileSystem = serviceProvider.GetRequiredService<IFileSystem>();
var logger = serviceProvider.GetRequiredService<IAnsiConsole>();
var appDataFolder = fileSystem.AspirateAppDataFolder();
var logoFilePath = fileSystem.Path.Combine(appDataFolder, AspirateLiterals.LogoDisabledFile);

await fileSystem.File.WriteAllTextAsync(logoFilePath, "1");
logger.MarkupLine($"[green]({EmojiLiterals.CheckMark}) Done:[/] The Aspir8 logo has been [blue]hidden[/].");

return 0;
}
}
1 change: 0 additions & 1 deletion src/Aspirate.Commands/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
global using Aspirate.Processors;
global using Aspirate.Processors.Resources.Dockerfile;
global using Aspirate.Processors.Transformation;
global using Aspirate.Secrets;
global using Aspirate.Shared.Enums;
global using Aspirate.Shared.Exceptions;
global using Aspirate.Shared.Extensions;
Expand Down
1 change: 1 addition & 0 deletions src/Aspirate.Services/Aspirate.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="CliWrap" />
<PackageReference Include="KubernetesClient" />
<PackageReference Include="NuGet.Protocol" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/Aspirate.Services/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
global using System.IO.Abstractions;
global using System.Reflection;
global using System.Runtime.InteropServices;
global using System.Security.Cryptography;
global using System.Text;
Expand Down Expand Up @@ -29,6 +30,10 @@
global using k8s;
global using k8s.Models;
global using Microsoft.Extensions.DependencyInjection;
global using NuGet.Common;
global using NuGet.Protocol;
global using NuGet.Protocol.Core.Types;
global using NuGet.Versioning;
global using Spectre.Console;
global using YamlDotNet.Serialization;
global using YamlDotNet.Serialization.NamingConventions;
Loading

0 comments on commit ddf340a

Please sign in to comment.