Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort firmware version output. Fix bug where firmware command was not… #458

Merged
merged 3 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
stevenkuhn marked this conversation as resolved.
Show resolved Hide resolved
{
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
Loading