diff --git a/Harp.Toolkit/Harp.Toolkit.csproj b/Harp.Toolkit/Harp.Toolkit.csproj
index 0c7a0df..076ea54 100644
--- a/Harp.Toolkit/Harp.Toolkit.csproj
+++ b/Harp.Toolkit/Harp.Toolkit.csproj
@@ -9,8 +9,8 @@
-
-
+
+
diff --git a/Harp.Toolkit/Program.cs b/Harp.Toolkit/Program.cs
index 00648b3..502a73a 100644
--- a/Harp.Toolkit/Program.cs
+++ b/Harp.Toolkit/Program.cs
@@ -8,41 +8,45 @@ internal class Program
{
static async Task Main(string[] args)
{
- var portName = new Option(
- name: "--port",
- description: "Specifies the name of the serial port used to communicate with the device."
- ) { IsRequired = true };
- portName.ArgumentHelpName = nameof(portName);
+ Option portNameOption = new("--port")
+ {
+ Description = "Specifies the name of the serial port used to communicate with the device.",
+ Required = true
+ };
- var portTimeout = new Option(
- name: "--timeout",
- description: "Specifies an optional timeout to receive a response from the device."
- ) { ArgumentHelpName = "milliseconds" };
+ Option portTimeoutOption = new("--timeout")
+ {
+ Description = "Specifies an optional timeout, in milliseconds, to receive a response from the device."
+ };
- var firmwarePath = new Option(
- name: "--path",
- description: "Specifies the path of the firmware file to write to the device."
- ) { IsRequired = true };
- firmwarePath.ArgumentHelpName = nameof(firmwarePath);
+ Option firmwarePathOption = new("--path")
+ {
+ Description = "Specifies the path of the firmware file to write to the device.",
+ Required = true
+ };
- var forceUpdate = new Option(
- name: "--force",
- description: "Indicates whether to force a firmware update on the device regardless of compatibility."
- );
+ Option forceUpdateOption = new("--force")
+ {
+ Description = "Indicates whether to force a firmware update on the device regardless of compatibility."
+ };
- var listCommand = new Command("list", description: "List all available system serial ports.");
- listCommand.SetHandler(() =>
+ var listCommand = new Command("list", description: "Lists all available system serial ports.");
+ listCommand.SetAction(parseResult =>
{
var portNames = SerialPort.GetPortNames();
Console.WriteLine($"PortNames: [{string.Join(", ", portNames)}]");
});
var updateCommand = new Command("update", description: "Update the device firmware from a local HEX file.");
- updateCommand.AddOption(portName);
- updateCommand.AddOption(firmwarePath);
- updateCommand.AddOption(forceUpdate);
- updateCommand.SetHandler(async (portName, firmwarePath, forceUpdate) =>
+ updateCommand.Options.Add(portNameOption);
+ updateCommand.Options.Add(firmwarePathOption);
+ updateCommand.Options.Add(forceUpdateOption);
+ updateCommand.SetAction(async parseResult =>
{
+ var firmwarePath = parseResult.GetRequiredValue(firmwarePathOption);
+ var portName = parseResult.GetRequiredValue(portNameOption);
+ var forceUpdate = parseResult.GetValue(forceUpdateOption);
+
var firmware = DeviceFirmware.FromFile(firmwarePath.FullName);
Console.WriteLine($"{firmware.Metadata}");
ProgressBar.Write(0);
@@ -52,15 +56,18 @@ static async Task Main(string[] args)
await Bootloader.UpdateFirmwareAsync(portName, firmware, forceUpdate, progress);
}
finally { Console.WriteLine(); }
- }, portName, firmwarePath, forceUpdate);
+ });
var rootCommand = new RootCommand("Tool for inspecting, updating and interfacing with Harp devices.");
- rootCommand.AddOption(portName);
- rootCommand.AddOption(portTimeout);
- rootCommand.AddCommand(listCommand);
- rootCommand.AddCommand(updateCommand);
- rootCommand.SetHandler(async (portName, portTimeout) =>
+ rootCommand.Options.Add(portNameOption);
+ rootCommand.Options.Add(portTimeoutOption);
+ rootCommand.Subcommands.Add(listCommand);
+ rootCommand.Subcommands.Add(updateCommand);
+ rootCommand.SetAction(async parseResult =>
{
+ var portName = parseResult.GetRequiredValue(portNameOption);
+ var portTimeout = parseResult.GetValue(portTimeoutOption);
+
using var device = new AsyncDevice(portName);
var whoAmI = await device.ReadWhoAmIAsync().WithTimeout(portTimeout);
var hardwareVersion = await device.ReadHardwareVersionAsync();
@@ -74,7 +81,9 @@ static async Task Main(string[] args)
Console.WriteLine($"Fw: {firmwareVersion.Major}.{firmwareVersion.Minor}");
Console.WriteLine($"Timestamp (s): {timestamp}");
Console.WriteLine();
- }, portName, portTimeout);
- await rootCommand.InvokeAsync(args);
+ });
+
+ var parseResult = rootCommand.Parse(args);
+ await parseResult.InvokeAsync();
}
}
diff --git a/global.json b/global.json
new file mode 100644
index 0000000..989a69c
--- /dev/null
+++ b/global.json
@@ -0,0 +1,6 @@
+{
+ "sdk": {
+ "version": "8.0.100",
+ "rollForward": "latestMinor"
+ }
+}
\ No newline at end of file