Skip to content

Commit

Permalink
Move string literals to Strings.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
CartBlanche committed May 21, 2024
1 parent 9a03fda commit 39c1e96
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
45 changes: 18 additions & 27 deletions Source/v2/Meadow.CLI/Commands/Current/Provision/ProvisionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace Meadow.CLI.Commands.Provision;

[Command("provision", Description = "Provision 1 or more devices that are in DFU mode.")]
public class ProvisionCommand : BaseDeviceCommand<ProvisionCommand>
public class ProvisionCommand : BaseSettingsCommand<ProvisionCommand>
{
public const string DefaultOSVersion = "1.11.0.0";
[CommandOption("version", 'v', Description = "Target OS version for devices to be provisioned with", IsRequired = false)]
Expand All @@ -26,16 +26,10 @@ public class ProvisionCommand : BaseDeviceCommand<ProvisionCommand>
private ObservableConcurrentQueue<BootLoaderDevice> bootloaderDeviceQueue = new ObservableConcurrentQueue<BootLoaderDevice>();
//private ObservableConcurrentQueue<BootLoaderDevice> processingDeviceQueue = new ObservableConcurrentQueue<BootLoaderDevice>();

private FileManager FileManager { get; }
private ISettingsManager Settings { get; }
private MeadowConnectionManager MeadowConnectionManager { get; }

public ProvisionCommand(ISettingsManager settingsManager, FileManager fileManager, MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
public ProvisionCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(settingsManager, loggerFactory)
{
FileManager = fileManager;
Settings = settingsManager;
MeadowConnectionManager = connectionManager;
}

protected override async ValueTask ExecuteCommand()
Expand All @@ -48,9 +42,11 @@ protected override async ValueTask ExecuteCommand()
osVersion = OsVersion;

// Install DFU, if it's not already installed.
var dfuInstallCommand = new DfuInstallCommand(Settings, LoggerFactory);
var dfuInstallCommand = new DfuInstallCommand(SettingsManager, LoggerFactory);
await dfuInstallCommand.ExecuteAsync(Console);

// Make sure we've downloaded the passed in osVersion or default
// Use Firmware Download command??
if (await MeadowCLI($"firmware download -v {osVersion} -f") == 0)
{
bool refreshDeviceList = false;
Expand All @@ -61,16 +57,16 @@ protected override async ValueTask ExecuteCommand()

if (bootloaderDeviceQueue.Count == 0)
{
Logger?.LogError($"No devices found in bootloader mode. Rerun this command when at least 1 connected device is in bootloader mode.");
Logger?.LogError(Strings.ProvisionNoDevicesFound);
return;
}

var multiSelectionPrompt = new MultiSelectionPrompt<BootLoaderDevice>()
.Title("Devices in Bootloader mode")
.Title(Strings.ProvisionTitle)
.PageSize(15)
.NotRequired() // Can be Blank to exit
.MoreChoicesText("More Choices")
.InstructionsText("Instructions")
.MoreChoicesText(Strings.ProvisionMoreChoicesInstructions)
.InstructionsText(Strings.ProvisionInstructions)
.UseConverter(x => x.SerialPort);

foreach (var device in bootloaderDeviceQueue)
Expand All @@ -81,7 +77,7 @@ protected override async ValueTask ExecuteCommand()
selectedDevices = AnsiConsole.Prompt(multiSelectionPrompt);

var selectedDeviceTable = new Table();
selectedDeviceTable.AddColumn("Selected Devices");
selectedDeviceTable.AddColumn(Strings.ProvisionColumnTitle);

foreach (var device in selectedDevices)
{
Expand All @@ -90,13 +86,13 @@ protected override async ValueTask ExecuteCommand()

AnsiConsole.Write(selectedDeviceTable);

refreshDeviceList = AnsiConsole.Confirm(Strings.ProvisionRefreshDeviceList);
refreshDeviceList = AnsiConsole.Confirm(Strings.ProvisionRefreshDeviceList);
} while (refreshDeviceList);


if (selectedDevices.Count == 0)
{
AnsiConsole.MarkupLine("[yellow]No devices selected to update[/]. Exiting.");
AnsiConsole.MarkupLine(Strings.ProvsionNoDeviceSelected);
return;
}
else
Expand All @@ -106,7 +102,7 @@ protected override async ValueTask ExecuteCommand()
await AnsiConsole.Status()
.Start("Thinking...", async ctx =>
{
AnsiConsole.MarkupLine($"Flashing [green]{item.SerialPort}[/]");
AnsiConsole.MarkupLine(Strings.ProvisionFlashingDevice, item.SerialPort);

if (await MeadowCLI($"firmware write -v {osVersion} -s {item.SerialNumber}") == 0)
{
Expand All @@ -116,7 +112,7 @@ await AnsiConsole.Status()
Logger?.LogError($"Error flash in {item.SerialPort} :(");
}
});

}
}
}
Expand All @@ -126,11 +122,6 @@ await AnsiConsole.Status()
}
}

private void FirmwareWriteCommand_FlashProgress(object? sender, FirmwareType e)
{
Logger?.LogInformation($"Writing {e}");
}

private async Task UpdateDeviceList(CancellationToken token)
{
var ourDevices = await GetValidUsbDevices();
Expand Down Expand Up @@ -212,6 +203,7 @@ static async Task<int> MeadowCLI(string arg, bool redirectStandardOutput = true,
{
using (var process = new Process())
{
// TODO Remove ./ before merging PR, otherwise it won't work
process.StartInfo.FileName = "./meadow";
process.StartInfo.Arguments = $"{arg}";
process.StartInfo.WorkingDirectory = System.AppContext.BaseDirectory;
Expand Down Expand Up @@ -239,5 +231,4 @@ internal class BootLoaderDevice
internal string SerialPort { get; set; } = string.Empty;
internal string SerialNumber { get; set; } = string.Empty;
internal string CurrentStatus { get; set; } = string.Empty;
}

}
7 changes: 7 additions & 0 deletions Source/v2/Meadow.Cli/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,11 @@ public static class Telemetry
public const string AppTrimFailed = "Application trimming failed";

public const string ProvisionRefreshDeviceList = "Reselect Bootloader devices (y=Refresh List, n=Flash selected devices)?";
public const string ProvisionMoreChoicesInstructions = "[grey](Move up and down to reveal more devices)[/]";
public const string ProvisionInstructions = "[grey](Press [blue]<space>[/] to toggle a device, [green]<enter>[/] to accept and flash the selected device)[/]";
public const string ProvisionTitle = "Devices in Bootloader mode";
public const string ProvisionNoDevicesFound = "No devices found in bootloader mode. Rerun this command when at least 1 connected device is in bootloader mode.";
public const string ProvisionColumnTitle = "Selected Devices";
public const string ProvsionNoDeviceSelected = "[yellow]No devices selected to provision[/]. Exiting.";
public const string ProvisionFlashingDevice = "Flashing [green]{0}[/]";
}

0 comments on commit 39c1e96

Please sign in to comment.