Skip to content

Commit

Permalink
Merge pull request #458 from WildernessLabs/bug/firmware-list
Browse files Browse the repository at this point in the history
sort firmware version output.  Fix bug where firmware command was not…
  • Loading branch information
ctacke committed Feb 10, 2024
2 parents de5a1d1 + 0cc3a4f commit b850ac0
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 29 deletions.
9 changes: 8 additions & 1 deletion Source/v2/Meadow.Cli/Commands/Current/BaseCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CliFx;
using CliFx.Exceptions;
using CliFx.Infrastructure;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
11 changes: 0 additions & 11 deletions Source/v2/Meadow.Cloud.Client/Firmware/FirmwareClient.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
namespace Meadow.Cloud.Client.Firmware;

public interface IFirmwareClient
{
Task<IEnumerable<GetFirmwareVersionsResponse>> GetVersions(string type, CancellationToken cancellationToken = default);

Task<GetFirmwareVersionResponse?> GetVersion(string type, string version, CancellationToken cancellationToken = default);

Task<HttpResponseMessage> GetDownloadResponse(string url, CancellationToken cancellationToken = default);

Task<HttpResponseMessage> GetDownloadResponse(Uri url, CancellationToken cancellationToken = default);
}

public class FirmwareClient : MeadowCloudClientBase, IFirmwareClient
{
private readonly HttpClient _httpClient;
Expand Down
12 changes: 12 additions & 0 deletions Source/v2/Meadow.Cloud.Client/Firmware/IFirmwareClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Meadow.Cloud.Client.Firmware;

public interface IFirmwareClient
{
Task<IEnumerable<GetFirmwareVersionsResponse>> GetVersions(string type, CancellationToken cancellationToken = default);

Task<GetFirmwareVersionResponse?> GetVersion(string type, string version, CancellationToken cancellationToken = default);

Task<HttpResponseMessage> GetDownloadResponse(string url, CancellationToken cancellationToken = default);

Task<HttpResponseMessage> GetDownloadResponse(Uri url, CancellationToken cancellationToken = default);
}
22 changes: 22 additions & 0 deletions Source/v2/Meadow.Cloud.Client/IMeadowCloudClient.cs
Original file line number Diff line number Diff line change
@@ -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<bool> Authenticate(string? host = default, CancellationToken cancellationToken = default);
}
20 changes: 6 additions & 14 deletions Source/v2/Meadow.Cloud.Client/MeadowCloudClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> Authenticate(string? host = default, CancellationToken cancellationToken = default);
}

public class MeadowCloudClient : IMeadowCloudClient
{
public const string DefaultHost = "https://www.meadowcloud.co";
Expand All @@ -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<MeadowCloudClient>? logger = default)
{
_firmwareClient = new Lazy<FirmwareClient>(() => new FirmwareClient(httpClient));

if (httpClient.BaseAddress == null)
{
httpClient.BaseAddress = new Uri(DefaultHost);
}

_httpClient = httpClient;
_identityManager = identityManager;
_logger = logger ?? NullLogger<MeadowCloudClient>.Instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b850ac0

Please sign in to comment.