From 8095737c68b977a9cc672f8174df29be063f2ecb Mon Sep 17 00:00:00 2001 From: glopesdev Date: Sun, 11 Jan 2026 16:09:34 +0000 Subject: [PATCH 1/2] Add global.json file --- global.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 global.json 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 From d31ab3537d71728cd9cbd243063911d63ab66d57 Mon Sep 17 00:00:00 2001 From: glopesdev Date: Sun, 11 Jan 2026 16:10:01 +0000 Subject: [PATCH 2/2] Update to latest System.CommandLine --- Harp.Toolkit/Harp.Toolkit.csproj | 4 +- Harp.Toolkit/Program.cs | 73 ++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 34 deletions(-) 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(); } }