Skip to content

Commit

Permalink
Formatting and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens committed Jan 15, 2024
1 parent 4dd98de commit c4ee4d7
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Source/v2/Meadow.CLI.Core/PackageManager/PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public static FileInfo[] GetAvailableBuiltConfigurations(string rootFolder, stri

// look for a 'bin' folder
var path = Path.Combine(rootFolder, "bin");
if (!Directory.Exists(path)) throw new FileNotFoundException($"No 'bin' directory found under {rootFolder}. Have you compiled?");
if (!Directory.Exists(path)) throw new FileNotFoundException($"No 'bin' directory found under {rootFolder}. Have you compiled?");

var files = new List<FileInfo>();
FindApp(path, files);
Expand Down
10 changes: 7 additions & 3 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppBuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public AppBuildCommand(IPackageManager packageManager, ILoggerFactory loggerFact
_packageManager = packageManager;
}

protected override async ValueTask ExecuteCommand()
protected override ValueTask ExecuteCommand()
{
string path = Path == null
? AppDomain.CurrentDomain.BaseDirectory
Expand All @@ -33,11 +33,14 @@ protected override async ValueTask ExecuteCommand()
if (!Directory.Exists(path))
{
Logger?.LogError($"Invalid application path '{path}'");
return;
return ValueTask.CompletedTask;
}
}

if (Configuration == null) Configuration = "Release";
if (Configuration == null)
{
Configuration = "Release";
}

Logger?.LogInformation($"Building {Configuration} configuration of {path}...");

Expand All @@ -52,5 +55,6 @@ protected override async ValueTask ExecuteCommand()
{
Logger?.LogError($"Build successful");
}
return ValueTask.CompletedTask;
}
}
3 changes: 1 addition & 2 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CliFx.Attributes;
using Meadow.CLI;
using Meadow.Hcom;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -69,7 +68,7 @@ protected override async ValueTask ExecuteCommand()
return;
}

// illink returns before all files are actually written. That's not fun, but we must just wait a little while.
// illink returns before all files are written - attempt a delay of 1s
await Task.Delay(1000);

if (!await DeployApplication(connection, path, CancellationToken))
Expand Down
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Commands/Current/BaseCloudCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ public BaseCloudCommand(

return org;
}
}
}
1 change: 0 additions & 1 deletion Source/v2/Meadow.Cli/Commands/Current/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ public async ValueTask ExecuteAsync(IConsole console)
Logger?.LogInformation($"Done");
}
}

}
5 changes: 2 additions & 3 deletions Source/v2/Meadow.Cli/Commands/Current/BaseFileCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Meadow.CLI;
using Meadow.Software;
using Meadow.Software;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;
Expand All @@ -13,4 +12,4 @@ public BaseFileCommand(FileManager fileManager, ISettingsManager settingsManager
{
FileManager = fileManager;
}
}
}
30 changes: 13 additions & 17 deletions Source/v2/Meadow.Cli/Commands/Current/DeveloperCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,29 @@ public class DeveloperCommand : BaseDeviceCommand<DeveloperCommand>

public DeveloperCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
{
}
{ }

protected override async ValueTask ExecuteCommand()
{
var connection = await GetCurrentConnection();

if (connection == null)
if (connection == null || connection.Device == null)
{
Logger?.LogError($"Developer parameter set failed - device or connection not found");
return;
}

Logger?.LogInformation($"Setting developer parameter {Parameter} to {Value}");

if (connection != null)
connection.DeviceMessageReceived += (s, e) =>
{
connection.DeviceMessageReceived += (s, e) =>
{
Logger?.LogInformation(e.message);
};
connection.ConnectionError += (s, e) =>
{
Logger?.LogError(e.Message);
};

await connection.Device.SetDeveloperParameter(Parameter, Value, CancellationToken);
}
}
}
Logger?.LogInformation(e.message);
};
connection.ConnectionError += (s, e) =>
{
Logger?.LogError(e.Message);
};

await connection.Device.SetDeveloperParameter(Parameter, Value, CancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Meadow.CLI.Commands.DeviceManagement;
[Command("device provision", Description = "Registers and prepares connected device for use with Meadow Cloud")]
public class DeviceProvisionCommand : BaseDeviceCommand<DeviceProvisionCommand>
{
private DeviceService _deviceService;
private readonly DeviceService _deviceService;

public const string DefaultHost = "https://www.meadowcloud.co";

Expand Down Expand Up @@ -75,9 +75,9 @@ protected override async ValueTask ExecuteCommand()

var connection = await GetCurrentConnection();

if (connection == null)
if (connection == null || connection.Device == null)
{
Logger?.LogError($"No connection path is defined");
Logger?.LogError($"Device provision failed - device or connection not found");
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CliFx.Attributes;
using Meadow.CLI;
using Meadow.CLI.Core.Internals.Dfu;
using Meadow.Hcom;
using Meadow.LibUsb;
Expand Down Expand Up @@ -58,7 +57,7 @@ protected override async ValueTask ExecuteCommand()

if (!Files.Contains(FirmwareType.OS) && UseDfu)
{
Logger?.LogError($"DFU is only used for OS files. Select an OS file or remove the DFU option");
Logger?.LogError($"DFU is only used for OS files - select an OS file or remove the DFU option");
return;
}

Expand Down Expand Up @@ -199,7 +198,7 @@ private ILibUsbDevice GetLibUsbDeviceForCurrentEnvironment()
_libUsbDevice = devices[0];
break;
default:
throw new Exception("Multiple devices found in bootloader mode. Disconnect all but one");
throw new Exception("Multiple devices found in bootloader mode - only connect one device");
}
}

Expand Down Expand Up @@ -298,7 +297,7 @@ private async ValueTask WriteFiles(IMeadowConnection connection)
write_runtime:
if (!await connection.Device.WriteRuntime(rtpath, CancellationToken))
{
Logger?.LogInformation($"Error writing runtime. Retrying.");
Logger?.LogInformation($"Error writing runtime - retrying");
goto write_runtime;
}
}
Expand Down
6 changes: 3 additions & 3 deletions Source/v2/Meadow.Cli/Commands/Current/ListenCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class ListenCommand : BaseDeviceCommand<ListenCommand>

public ListenCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
{
}
{ }

private void Connection_ConnectionMessage(object? sender, string e)
{
//ToDo
}

private void OnDeviceMessageReceived(object? sender, (string message, string? source) e)
Expand Down Expand Up @@ -49,4 +49,4 @@ protected override async ValueTask ExecuteCommand()
await Task.Delay(1000);
}
}
}
}
3 changes: 1 addition & 2 deletions Source/v2/Meadow.Cli/Commands/Legacy/DownloadOsCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CliFx.Attributes;
using Meadow.CLI;
using Meadow.Software;
using Microsoft.Extensions.Logging;

Expand All @@ -11,6 +10,6 @@ public class DownloadOsCommand : FirmwareDownloadCommand
public DownloadOsCommand(FileManager fileManager, ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(fileManager, settingsManager, loggerFactory)
{
Logger?.LogWarning($"Deprecated command. Use `firmware download` instead");
Logger?.LogWarning($"Deprecated command - use `firmware download` instead");
}
}
16 changes: 9 additions & 7 deletions Source/v2/Meadow.Cli/Commands/Legacy/FlashOsCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CliFx.Attributes;
using Meadow.CLI;
using Meadow.CLI.Core.Internals.Dfu;
using Meadow.LibUsb;
using Meadow.Software;
Expand All @@ -11,7 +10,7 @@ namespace Meadow.CLI.Commands.DeviceManagement;
public class FlashOsCommand : BaseDeviceCommand<FlashOsCommand>
{
[CommandOption("osFile", 'o', Description = "Path to the Meadow OS binary")]
public string OSFile { get; init; }
public string OSFile { get; init; } = default!;

[CommandOption("runtimeFile", 'r', Description = "Path to the Meadow Runtime binary")]
public string RuntimeFile { get; init; }
Expand Down Expand Up @@ -39,10 +38,13 @@ public class FlashOsCommand : BaseDeviceCommand<FlashOsCommand>

private ILibUsbDevice? _libUsbDevice;

public FlashOsCommand(ISettingsManager settingsManager, FileManager fileManager, MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
public FlashOsCommand(ISettingsManager settingsManager,
FileManager fileManager,
MeadowConnectionManager connectionManager,
ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
{
Logger?.LogWarning($"Deprecated command. Use `firmware write` instead");
Logger?.LogWarning($"Deprecated command. Use `firmware write` instead");

FileManager = fileManager;
Settings = settingsManager;
Expand Down Expand Up @@ -72,7 +74,7 @@ protected override async ValueTask ExecuteCommand()

if (!Files.Contains(FirmwareType.OS) && UseDfu)
{
Logger.LogError($"DFU is only used for OS files. Select an OS file or remove the DFU option");
Logger.LogError($"DFU is only used for OS files - select an OS file or remove the DFU option");
return;
}

Expand Down Expand Up @@ -196,7 +198,7 @@ private ILibUsbDevice GetLibUsbDeviceForCurrentEnvironment()
case 1:
return devices[0];
default:
throw new Exception("Multiple devices found in bootloader mode. Disconnect all but one");
throw new Exception("Multiple devices found in bootloader mode - only connect one device");
}
}

Expand Down Expand Up @@ -328,4 +330,4 @@ await DfuUtils.FlashFile(
logger: Logger,
format: DfuUtils.DfuFlashFormat.ConsoleOut);
}
}
}
6 changes: 2 additions & 4 deletions Source/v2/Meadow.Cli/Commands/Legacy/InstallDfuCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CliFx.Attributes;
using Meadow.CLI;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;
Expand All @@ -10,7 +9,6 @@ public class InstallDfuCommand : DfuInstallCommand
public InstallDfuCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(settingsManager, loggerFactory, "0.11")
{
Logger?.LogWarning($"Deprecated command. Use `dfu install` instead");
Logger?.LogWarning($"Deprecated command - use `dfu install` instead");
}
}

}
6 changes: 2 additions & 4 deletions Source/v2/Meadow.Cli/Commands/Legacy/ListPortsCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CliFx.Attributes;
using Meadow.CLI;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;
Expand All @@ -10,12 +9,11 @@ public class ListPortsCommand : PortListCommand
public ListPortsCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(loggerFactory)
{
Logger?.LogWarning($"Deprecated command. Use `port list` instead");
Logger?.LogWarning($"Deprecated command - use `port list` instead");
}

protected override ValueTask ExecuteCommand()
{
return base.ExecuteCommand();
}
}

}
4 changes: 2 additions & 2 deletions Source/v2/Meadow.Cli/Commands/Legacy/MonoDisableCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class MonoDisableCommand : RuntimeDisableCommand
public MonoDisableCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
{
Logger?.LogWarning($"Deprecated command. Use `runtime disable` instead");
Logger?.LogWarning($"Deprecated command - use `runtime disable` instead");
}
}
}
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Commands/Legacy/MonoEnableCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class MonoEnableCommand : RuntimeEnableCommand
public MonoEnableCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
{
Logger.LogWarning($"Deprecated command. Use `runtime enable` instead");
Logger?.LogWarning($"Deprecated command - use `runtime enable` instead");
}
}
4 changes: 2 additions & 2 deletions Source/v2/Meadow.Cli/Commands/Legacy/MonoStateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class MonoStateCommand : RuntimeStateCommand
public MonoStateCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
: base(connectionManager, loggerFactory)
{
Logger.LogWarning($"Deprecated command. Use `runtime state` instead");
Logger?.LogWarning($"Deprecated command - use `runtime state` instead");
}
}
}
8 changes: 3 additions & 5 deletions Source/v2/Meadow.Cli/Commands/Legacy/UsePortCommand.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using CliFx.Attributes;
using Meadow.CLI;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;

[Command("use port", Description = "** Deprecated ** Use `config route` instead")]
public class UsePortCommand : BaseCommand<UsePortCommand>
{
private ISettingsManager _settingsManager;
private readonly ISettingsManager _settingsManager;

[CommandParameter(0, Name = "Port", IsRequired = true)]
public string Port { get; set; } = default!;

public UsePortCommand(ILoggerFactory loggerFactory, ISettingsManager settingsManager)
: base(loggerFactory)
{
Logger?.LogWarning($"Deprecated command. Use `config route` instead");
Logger?.LogWarning($"Deprecated command -use `config route` instead");
_settingsManager = settingsManager;
}

Expand All @@ -26,5 +25,4 @@ protected override ValueTask ExecuteCommand()

return ValueTask.CompletedTask;
}
}

}
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Hcom/Connections/SerialConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void Detach()
// search for the device via HCOM - we'll use a simple command since we don't have a "ping"
var command = RequestBuilder.Build<GetDeviceInfoRequest>();

// sequence numbers are only for file retrieval. Setting it to non-zero will cause it to hang
// sequence numbers are only for file retrieval - Setting it to non-zero will cause it to hang

_port.DiscardInBuffer();

Expand Down

0 comments on commit c4ee4d7

Please sign in to comment.