From 2015d73cf0f3cb8597a41f8a69e2c5e2247218f0 Mon Sep 17 00:00:00 2001 From: Dominique Louis Date: Wed, 22 May 2024 10:03:23 +0100 Subject: [PATCH] Refactored strings, to follow Steven's static string class fexample and moved formatting out, as agreed. --- .../Current/Project/ProjectInstallCommand.cs | 4 +-- .../Current/Project/ProjectNewCommand.cs | 24 +++++++------- Source/v2/Meadow.Cli/Strings.cs | 33 ++++++++++++------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/Source/v2/Meadow.CLI/Commands/Current/Project/ProjectInstallCommand.cs b/Source/v2/Meadow.CLI/Commands/Current/Project/ProjectInstallCommand.cs index cdb3a3b5..fddf5658 100644 --- a/Source/v2/Meadow.CLI/Commands/Current/Project/ProjectInstallCommand.cs +++ b/Source/v2/Meadow.CLI/Commands/Current/Project/ProjectInstallCommand.cs @@ -19,7 +19,7 @@ public ProjectInstallCommand(ILoggerFactory loggerFactory) protected override async ValueTask ExecuteCommand() { - AnsiConsole.MarkupLine(Strings.ProjectInstallTemplatesTitle); + AnsiConsole.MarkupLine(Strings.ProjectTemplates.InstallTitle); // Install the templates (if they already exist it will update to the newest ones) _ = await AppTools.RunDotNetCommand("dotnet", $"new install WildernessLabs.Meadow.Template", CancellationToken); @@ -53,7 +53,7 @@ protected override async ValueTask ExecuteCommand() table.AddRow(longName, languages); } } - AnsiConsole.WriteLine(Strings.ProjectInstallTemplatesInstalled); + AnsiConsole.WriteLine(Strings.ProjectTemplates.Installed); // Render the table to the console AnsiConsole.Write(table); diff --git a/Source/v2/Meadow.CLI/Commands/Current/Project/ProjectNewCommand.cs b/Source/v2/Meadow.CLI/Commands/Current/Project/ProjectNewCommand.cs index c0a0e7e9..7a52a91d 100644 --- a/Source/v2/Meadow.CLI/Commands/Current/Project/ProjectNewCommand.cs +++ b/Source/v2/Meadow.CLI/Commands/Current/Project/ProjectNewCommand.cs @@ -12,7 +12,7 @@ namespace Meadow.CLI.Commands.Current.Project [Command("project new", Description = "Shows a list of project templates to choose from.")] public class ProjectNewCommand : BaseCommand { - [CommandOption('o', Description = Strings.ProjectNewOutputPath, IsRequired = false)] + [CommandOption('o', Description = Strings.ProjectTemplates.OutputPath, IsRequired = false)] public string? OutputPath { get; private set; } [CommandOption('l', Description = "Generate the projects using the language specific. Valid values are C# or F# or VB", IsRequired = false)] @@ -28,11 +28,11 @@ public ProjectNewCommand(ILoggerFactory loggerFactory) protected override async ValueTask ExecuteCommand() { - AnsiConsole.MarkupLine(Strings.ProjectNewProjectTemplatesTitle); + AnsiConsole.MarkupLine(Strings.ProjectTemplates.WizardTitle); List templateTable = await GetInstalledTempaltes(); // Ask some pertinent questions - var projectName = AnsiConsole.Ask(Strings.ProjectNewProjectName); + var projectName = AnsiConsole.Ask(Strings.ProjectTemplates.ProjectName); string outputPathArgument; if (!string.IsNullOrWhiteSpace(OutputPath)) @@ -45,7 +45,7 @@ protected override async ValueTask ExecuteCommand() OutputPath = projectName; } - var generateSln = AnsiConsole.Confirm(Strings.ProjectNewGenerateSln); + var generateSln = AnsiConsole.Confirm(Strings.ProjectTemplates.GenerateSln); // Extract template names from the output var templateList = templateTable @@ -61,11 +61,11 @@ protected override async ValueTask ExecuteCommand() startKitGroup = PopulateTemplateList(templateList, templateNames, startKitGroup, startKitTemplates); var multiSelectionPrompt = new MultiSelectionPrompt() - .Title(Strings.ProjectNewInstalledTemplates) + .Title(Strings.ProjectTemplates.InstalledTemplates) .PageSize(15) .NotRequired() // Can be Blank to exit - .MoreChoicesText(Strings.ProjectNewMoreChoicesInstructions) - .InstructionsText(Strings.ProjectNewInstructions) + .MoreChoicesText(string.Format($"[grey]{Strings.ProjectTemplates.MoreChoicesInstructions}[/]")) + .InstructionsText(string.Format($"[grey]{Strings.ProjectTemplates.Instructions}[/]", $"[blue]<{Strings.Space}>[/]", $"[green]<{Strings.Enter}>[/]")) .UseConverter(x => x.Name); // I wanted StartKit to appear 1st, if it exists @@ -84,7 +84,7 @@ protected override async ValueTask ExecuteCommand() } else { - AnsiConsole.MarkupLine(Strings.ProjectNewNoTemplateSelected); + AnsiConsole.MarkupLine($"[yellow]{Strings.ProjectTemplates.NoTemplateSelected}[/]"); } } @@ -94,7 +94,7 @@ private async Task GenerateProjectsFromSelectedTemplates(string projectName, str // Create the selected templates foreach (var selectedTemplate in selectedTemplates) { - AnsiConsole.MarkupLine(Strings.ProjectNewCreatingProject, selectedTemplate.Name); + AnsiConsole.MarkupLine($"[green]{Strings.ProjectTemplates.CreatingProject}[/]", selectedTemplate.Name); var outputPath = string.Empty; if (selectedTemplate.Name.Contains(StartKit)) @@ -122,7 +122,7 @@ private async Task GenerateProjectsFromSelectedTemplates(string projectName, str if (generateSln) { - AnsiConsole.MarkupLine(Strings.ProjectNewCreatingSln); + AnsiConsole.MarkupLine($"[green]{Strings.ProjectTemplates.CreatingSln}[/]"); // Create the sln _ = await AppTools.RunDotNetCommand("dotnet", $"new sln -n {projectName} -o {OutputPath} --force", CancellationToken); @@ -157,7 +157,7 @@ private async Task GenerateProjectsFromSelectedTemplates(string projectName, str OpenSolution(slnFilePath); } - AnsiConsole.MarkupLine(Strings.ProjectNewProjectGenerationComplete, projectName); + AnsiConsole.MarkupLine(Strings.ProjectTemplates.GenerationComplete, $"[green]{projectName}[/]"); } private static MeadowTemplate? PopulateTemplateList(List templateList, List templateNames, MeadowTemplate? startKitGroup, List startKitTemplates) @@ -204,7 +204,7 @@ private async Task> GetInstalledTempaltes() // If not templates exists, then for now we automagically install them before proceeding if (templateTable.Count == 0) { - AnsiConsole.MarkupLine(Strings.ProjectNewNoTemplatesFound); + AnsiConsole.MarkupLine($"[yellow]{Strings.ProjectTemplates.NoTemplatesFound}[/]"); var projectInstallCommand = new ProjectInstallCommand(LoggerFactory); await projectInstallCommand.ExecuteAsync(Console); diff --git a/Source/v2/Meadow.Cli/Strings.cs b/Source/v2/Meadow.Cli/Strings.cs index 58d2c159..f94684d9 100644 --- a/Source/v2/Meadow.Cli/Strings.cs +++ b/Source/v2/Meadow.Cli/Strings.cs @@ -90,16 +90,25 @@ public static class Telemetry public const string AskToParticipate = "Would you like to participate?"; } - public const string ProjectNewOutputPath = "The path where you would like the projects created."; - public const string ProjectNewProjectTemplatesTitle = "Meadow Project Wizard..."; - public const string ProjectNewProjectName = "What is your project's name?"; - public const string ProjectNewProjectGenerationComplete = "All of [green]{0}'s[/] projects have now been created!"; - public const string ProjectNewGenerateSln = "Create an sln that contains all the new projects?"; - public const string ProjectNewNoTemplatesFound = "[yellow]No Meadow project templates found[/].\n"; - public const string ProjectNewInstalledTemplates = "--- Installed Templates ---"; - public const string ProjectNewMoreChoicesInstructions = "[grey](Move up and down to reveal more templates)[/]"; - public const string ProjectNewInstructions = "[grey](Press [blue][/] to toggle a template, [green][/] to accept and generate the selected templates)[/]"; - public const string ProjectNewCreatingProject = "[green]Creating {0} project[/]"; - public const string ProjectNewCreatingSln = "[green]Creating sln for selected projects....[/]"; - public const string ProjectNewNoTemplateSelected = "[yellow]No templates selected.[/]"; + public static class ProjectTemplates + { + public const string InstallTitle = "Installing and updating the Meadow Project Templates"; + public const string Installed = "The following Meadow Project Templates are now installed."; + + public const string OutputPath = "The path where you would like the projects created."; + public const string WizardTitle = "Meadow Project Wizard..."; + public const string ProjectName = "What is your project's name?"; + public const string GenerationComplete = "All of {0}'s projects have now been created!"; + public const string GenerateSln = "Create an sln that contains all the new projects?"; + public const string NoTemplatesFound = "No Meadow project templates found.\n"; + public const string InstalledTemplates = "--- Installed Templates ---"; + public const string MoreChoicesInstructions = "(Move up and down to reveal more templates)"; + public const string Instructions = "Press {0} to toggle a template or {1} to accept and generate the selected templates)"; + public const string CreatingProject = "Creating {0} project"; + public const string CreatingSln = "Creating sln for selected projects...."; + public const string NoTemplateSelected = "No templates selected."; + } + + public const string Enter = "Enter"; + public const string Space = "Space"; } \ No newline at end of file