-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
53d6bdc
commit ddf340a
Showing
17 changed files
with
378 additions
and
20 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
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
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
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
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
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,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
121
src/Aspirate.Commands/Commands/Settings/SettingsCommand.cs
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,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; | ||
} | ||
} |
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
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
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.