Skip to content

Commit

Permalink
Refactored strings, to follow Steven's static string class fexample a…
Browse files Browse the repository at this point in the history
…nd moved formatting out, as agreed.
  • Loading branch information
CartBlanche committed May 22, 2024
1 parent 99b4062 commit 2015d73
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions Source/v2/Meadow.CLI/Commands/Current/Project/ProjectNewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProjectNewCommand>
{
[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)]
Expand All @@ -28,11 +28,11 @@ public ProjectNewCommand(ILoggerFactory loggerFactory)

protected override async ValueTask ExecuteCommand()
{
AnsiConsole.MarkupLine(Strings.ProjectNewProjectTemplatesTitle);
AnsiConsole.MarkupLine(Strings.ProjectTemplates.WizardTitle);
List<string> templateTable = await GetInstalledTempaltes();

// Ask some pertinent questions
var projectName = AnsiConsole.Ask<string>(Strings.ProjectNewProjectName);
var projectName = AnsiConsole.Ask<string>(Strings.ProjectTemplates.ProjectName);

string outputPathArgument;
if (!string.IsNullOrWhiteSpace(OutputPath))
Expand All @@ -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
Expand All @@ -61,11 +61,11 @@ protected override async ValueTask ExecuteCommand()
startKitGroup = PopulateTemplateList(templateList, templateNames, startKitGroup, startKitTemplates);

var multiSelectionPrompt = new MultiSelectionPrompt<MeadowTemplate>()
.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
Expand All @@ -84,7 +84,7 @@ protected override async ValueTask ExecuteCommand()
}
else
{
AnsiConsole.MarkupLine(Strings.ProjectNewNoTemplateSelected);
AnsiConsole.MarkupLine($"[yellow]{Strings.ProjectTemplates.NoTemplateSelected}[/]");
}
}

Expand All @@ -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))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<string> templateList, List<MeadowTemplate> templateNames, MeadowTemplate? startKitGroup, List<MeadowTemplate> startKitTemplates)
Expand Down Expand Up @@ -204,7 +204,7 @@ private async Task<List<string>> 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);
Expand Down
33 changes: 21 additions & 12 deletions Source/v2/Meadow.Cli/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]<space>[/] to toggle a template, [green]<enter>[/] 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";
}

0 comments on commit 2015d73

Please sign in to comment.