Skip to content

Commit

Permalink
Add Mac and Linux support to dfu install. Refactor to centralis Proce…
Browse files Browse the repository at this point in the history
…ss launching and use more modern pattern.
  • Loading branch information
CartBlanche committed Jun 27, 2024
1 parent b1f21c6 commit 0d3fa1e
Show file tree
Hide file tree
Showing 3 changed files with 409 additions and 138 deletions.
36 changes: 16 additions & 20 deletions Source/v2/Meadow.Cli/Commands/Current/Dfu/DfuInstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace Meadow.CLI.Commands.DeviceManagement;
[Command("dfu install", Description = "Install dfu-util to the host operating system")]
public class DfuInstallCommand : BaseSettingsCommand<AppDeployCommand>
{
public const string DefaultVersion = "0.11";

[CommandOption("version", 'v', IsRequired = false)]
public string? Version { get; set; }

Expand All @@ -27,7 +25,7 @@ public DfuInstallCommand(ISettingsManager settingsManager, ILoggerFactory logger

protected override async ValueTask ExecuteCommand()
{
Version ??= DefaultVersion;
Version ??= DfuUtils.DEFAULT_DFU_VERSION;

switch (Version)
{
Expand All @@ -40,32 +38,30 @@ protected override async ValueTask ExecuteCommand()
return;
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
bool successfullyInstalled = false;
try
{
if (IsAdministrator())
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
try
{
await DfuUtils.InstallDfuUtil(FileManager.WildernessTempFolderPath, Version, CancellationToken);
}
catch (Exception ex)
{
throw new CommandException($"Failed to install DFU {Version}: " + ex.Message);
}
Logger?.LogInformation($"DFU {Version} installed successfully");
successfullyInstalled = await DfuUtils.CheckIfDfuUtilIsInstalledOnWindows(FileManager.WildernessTempFolderPath, Version, CancellationToken);
}
else
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Logger?.LogError("To install DFU on Windows, you'll need to run the command as an Administrator");
successfullyInstalled = await DfuUtils.CheckIfDfuUtilIsInstalledOnMac(Version, CancellationToken);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
successfullyInstalled = await DfuUtils.CheckIfDfuUtilIsInstalledOnLinux(Version, CancellationToken);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
catch (Exception ex)
{
Logger?.LogWarning("To install DFU on macOS, run: brew install dfu-util");
throw new CommandException($"Failed to install DFU {Version}: " + ex.Message);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))

if (successfullyInstalled)
{
Logger?.LogWarning("To install DFU on Linux, use the package manager to install the dfu-util package");
Logger?.LogInformation($"DFU Is installed");
}
}

Expand Down
Loading

0 comments on commit 0d3fa1e

Please sign in to comment.