diff --git a/Source/v2/Meadow.CLI/Commands/Current/Provision/ProvisionCommand.cs b/Source/v2/Meadow.CLI/Commands/Current/Provision/ProvisionCommand.cs index 14638348..38971ed2 100644 --- a/Source/v2/Meadow.CLI/Commands/Current/Provision/ProvisionCommand.cs +++ b/Source/v2/Meadow.CLI/Commands/Current/Provision/ProvisionCommand.cs @@ -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 +public class ProvisionCommand : BaseSettingsCommand { public const string DefaultOSVersion = "1.11.0.0"; [CommandOption("version", 'v', Description = "Target OS version for devices to be provisioned with", IsRequired = false)] @@ -26,16 +26,10 @@ public class ProvisionCommand : BaseDeviceCommand private ObservableConcurrentQueue bootloaderDeviceQueue = new ObservableConcurrentQueue(); //private ObservableConcurrentQueue processingDeviceQueue = new ObservableConcurrentQueue(); - 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() @@ -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; @@ -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() - .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) @@ -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) { @@ -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 @@ -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) { @@ -116,7 +112,7 @@ await AnsiConsole.Status() Logger?.LogError($"Error flash in {item.SerialPort} :("); } }); - + } } } @@ -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(); @@ -212,6 +203,7 @@ static async Task 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; @@ -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; -} - +} \ No newline at end of file diff --git a/Source/v2/Meadow.Cli/Strings.cs b/Source/v2/Meadow.Cli/Strings.cs index faa88c48..58546582 100644 --- a/Source/v2/Meadow.Cli/Strings.cs +++ b/Source/v2/Meadow.Cli/Strings.cs @@ -87,4 +87,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][/] to toggle a device, [green][/] 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}[/]"; } \ No newline at end of file