diff --git a/Source/v2/Meadow.Cli/Commands/Current/BaseCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/BaseCommand.cs index e0bc422f..944b09fd 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/BaseCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/BaseCommand.cs @@ -1,4 +1,5 @@ using CliFx; +using CliFx.Exceptions; using CliFx.Infrastructure; using Microsoft.Extensions.Logging; @@ -31,12 +32,18 @@ public async ValueTask ExecuteAsync(IConsole console) catch (Exception ex) { Logger?.LogError(ex.Message); - return; + throw new CommandException( + message: ex.Message, + exitCode: 1, + innerException: ex); } if (CancellationToken.IsCancellationRequested) { Logger?.LogInformation($"Cancelled"); + throw new CommandException( + message: "Cancelled", + exitCode: 2); } } } \ No newline at end of file diff --git a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareListCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareListCommand.cs index 7140fb31..7a1c6232 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareListCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareListCommand.cs @@ -44,7 +44,7 @@ private async Task DisplayVerboseResults(FileManager manager) Logger?.LogInformation($" {name}"); var collection = manager.Firmware[name]; - foreach (var package in collection) + foreach (var package in collection.OrderByDescending(p => p.Version)) { if (package == collection.DefaultPackage) { @@ -85,7 +85,7 @@ private async Task DisplayTerseResults(FileManager manager) Logger?.LogInformation($" {name}"); var collection = manager.Firmware[name]; - foreach (var package in collection) + foreach (var package in collection.OrderByDescending(p => p.Version)) { if (package == collection.DefaultPackage) { diff --git a/Source/v2/Meadow.Cloud.Client/Firmware/FirmwareClient.cs b/Source/v2/Meadow.Cloud.Client/Firmware/FirmwareClient.cs index 4db0089a..a0cbbfe6 100644 --- a/Source/v2/Meadow.Cloud.Client/Firmware/FirmwareClient.cs +++ b/Source/v2/Meadow.Cloud.Client/Firmware/FirmwareClient.cs @@ -1,16 +1,5 @@ namespace Meadow.Cloud.Client.Firmware; -public interface IFirmwareClient -{ - Task> GetVersions(string type, CancellationToken cancellationToken = default); - - Task GetVersion(string type, string version, CancellationToken cancellationToken = default); - - Task GetDownloadResponse(string url, CancellationToken cancellationToken = default); - - Task GetDownloadResponse(Uri url, CancellationToken cancellationToken = default); -} - public class FirmwareClient : MeadowCloudClientBase, IFirmwareClient { private readonly HttpClient _httpClient; diff --git a/Source/v2/Meadow.Cloud.Client/Firmware/IFirmwareClient.cs b/Source/v2/Meadow.Cloud.Client/Firmware/IFirmwareClient.cs new file mode 100644 index 00000000..41777d88 --- /dev/null +++ b/Source/v2/Meadow.Cloud.Client/Firmware/IFirmwareClient.cs @@ -0,0 +1,12 @@ +namespace Meadow.Cloud.Client.Firmware; + +public interface IFirmwareClient +{ + Task> GetVersions(string type, CancellationToken cancellationToken = default); + + Task GetVersion(string type, string version, CancellationToken cancellationToken = default); + + Task GetDownloadResponse(string url, CancellationToken cancellationToken = default); + + Task GetDownloadResponse(Uri url, CancellationToken cancellationToken = default); +} diff --git a/Source/v2/Meadow.Cloud.Client/IMeadowCloudClient.cs b/Source/v2/Meadow.Cloud.Client/IMeadowCloudClient.cs new file mode 100644 index 00000000..192d2879 --- /dev/null +++ b/Source/v2/Meadow.Cloud.Client/IMeadowCloudClient.cs @@ -0,0 +1,22 @@ +using Meadow.Cloud.Client.ApiTokens; +using Meadow.Cloud.Client.Collections; +using Meadow.Cloud.Client.Commands; +using Meadow.Cloud.Client.Devices; +using Meadow.Cloud.Client.Firmware; +using Meadow.Cloud.Client.Packages; +using Meadow.Cloud.Client.Users; + +namespace Meadow.Cloud.Client; + +public interface IMeadowCloudClient +{ + IApiTokenClient ApiToken { get; } + ICollectionClient Collection { get; } + ICommandClient Command { get; } + IDeviceClient Device { get; } + IFirmwareClient Firmware { get; } + IPackageClient Package { get; } + IUserClient User { get; } + + Task Authenticate(string? host = default, CancellationToken cancellationToken = default); +} diff --git a/Source/v2/Meadow.Cloud.Client/MeadowCloudClient.cs b/Source/v2/Meadow.Cloud.Client/MeadowCloudClient.cs index b84e39f5..3beefe8d 100644 --- a/Source/v2/Meadow.Cloud.Client/MeadowCloudClient.cs +++ b/Source/v2/Meadow.Cloud.Client/MeadowCloudClient.cs @@ -8,19 +8,6 @@ namespace Meadow.Cloud.Client; -public interface IMeadowCloudClient -{ - IApiTokenClient ApiToken { get; } - ICollectionClient Collection { get; } - ICommandClient Command { get; } - IDeviceClient Device { get; } - IFirmwareClient Firmware { get; } - IPackageClient Package { get; } - IUserClient User { get; } - - Task Authenticate(string? host = default, CancellationToken cancellationToken = default); -} - public class MeadowCloudClient : IMeadowCloudClient { public const string DefaultHost = "https://www.meadowcloud.co"; @@ -29,11 +16,16 @@ public class MeadowCloudClient : IMeadowCloudClient private readonly HttpClient _httpClient; private readonly IdentityManager _identityManager; private readonly ILogger _logger; - + public MeadowCloudClient(HttpClient httpClient, IdentityManager identityManager, MeadowCloudUserAgent userAgent, ILogger? logger = default) { _firmwareClient = new Lazy(() => new FirmwareClient(httpClient)); + if (httpClient.BaseAddress == null) + { + httpClient.BaseAddress = new Uri(DefaultHost); + } + _httpClient = httpClient; _identityManager = identityManager; _logger = logger ?? NullLogger.Instance; diff --git a/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs b/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs index 8070c2a7..151eeaf0 100644 --- a/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs +++ b/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs @@ -152,7 +152,11 @@ public Task Refresh() { _f7Packages.Clear(); - foreach (var directory in Directory.GetDirectories(PackageFileRoot)) + var directories = Directory + .GetDirectories(PackageFileRoot) + .OrderByDescending(d => d); + + foreach (var directory in directories) { var hasFiles = false;