Skip to content

Commit 161e35d

Browse files
authored
Fix help message showing despite operation executed (#68)
***NO_CI***
1 parent c2cb6ce commit 161e35d

File tree

2 files changed

+42
-34
lines changed

2 files changed

+42
-34
lines changed

nanoFirmwareFlasher/Program.cs

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ private static Task HandleErrorsAsync(IEnumerable<Error> errors)
121121

122122
static async Task RunOptionsAndReturnExitCodeAsync(Options o)
123123
{
124+
bool operationPerformed = false;
125+
124126
#region parse verbosity option
125127

126128
switch (o.Verbosity)
@@ -333,11 +335,14 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
333335
{
334336
// backup path specified, backup deployment
335337
_exitCode = Esp32Operations.BackupFlash(espTool, esp32Device, o.BackupPath, o.BackupFile, _verbosityLevel);
338+
336339
if (_exitCode != ExitCodes.OK)
337340
{
338341
// done here
339342
return;
340343
}
344+
345+
operationPerformed = true;
341346
}
342347
catch (ReadEsp32FlashException ex)
343348
{
@@ -470,22 +475,16 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
470475
{
471476
_exitCode = Stm32Operations.InstallDfuDrivers(_verbosityLevel);
472477

473-
if (_exitCode != ExitCodes.OK)
474-
{
475-
// done here
476-
return;
477-
}
478+
// done here
479+
return;
478480
}
479481

480482
if (o.InstallJtagDrivers)
481483
{
482484
_exitCode = Stm32Operations.InstallJtagDrivers(_verbosityLevel);
483485

484-
if (_exitCode != ExitCodes.OK)
485-
{
486-
// done here
487-
return;
488-
}
486+
// done here
487+
return;
489488
}
490489

491490
if (o.ListDevicesInDfuMode)
@@ -712,6 +711,8 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
712711
updateInterface,
713712
_verbosityLevel);
714713

714+
operationPerformed = true;
715+
715716
if (_exitCode != ExitCodes.OK)
716717
{
717718
// done here
@@ -767,6 +768,8 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
767768
updateInterface,
768769
_verbosityLevel);
769770

771+
operationPerformed = true;
772+
770773
if (_exitCode != ExitCodes.OK)
771774
{
772775
// done here
@@ -814,14 +817,10 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
814817
{
815818
if (o.TIInstallXdsDrivers)
816819
{
817-
818820
_exitCode = CC13x26x2Operations.InstallXds110Drivers(_verbosityLevel);
819821

820-
if (_exitCode != ExitCodes.OK)
821-
{
822-
// done here
823-
return;
824-
}
822+
// done here
823+
return;
825824
}
826825

827826
if (!string.IsNullOrEmpty(o.TargetName))
@@ -849,6 +848,8 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
849848
appFlashAddress,
850849
_verbosityLevel);
851850

851+
operationPerformed = true;
852+
852853
if (_exitCode != ExitCodes.OK)
853854
{
854855
// done here
@@ -884,6 +885,8 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
884885
appFlashAddress,
885886
_verbosityLevel);
886887

888+
operationPerformed = true;
889+
887890
if (_exitCode != ExitCodes.OK)
888891
{
889892
// done here
@@ -906,23 +909,26 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
906909

907910
#endregion
908911

909-
// done nothing...
910-
// because of short-comings in CommandLine parsing
911-
// need to customize the output to provide a consistent output
912-
var parser = new Parser(config => config.HelpWriter = null);
913-
var result = parser.ParseArguments<Options>(new[] { "", "" });
914-
915-
var helpText = new HelpText(
916-
new HeadingInfo(_headerInfo),
917-
_copyrightInfo)
918-
.AddPreOptionsLine("")
919-
.AddPreOptionsLine("No operation was performed with the options supplied.")
920-
.AddPreOptionsLine("")
921-
.AddPreOptionsLine(HelpText.RenderUsageText(result))
922-
.AddPreOptionsLine("")
923-
.AddOptions(result);
924-
925-
Console.WriteLine(helpText.ToString());
912+
// done nothing... or maybe not...
913+
if (!operationPerformed)
914+
{
915+
// because of short-comings in CommandLine parsing
916+
// need to customize the output to provide a consistent output
917+
var parser = new Parser(config => config.HelpWriter = null);
918+
var result = parser.ParseArguments<Options>(new[] { "", "" });
919+
920+
var helpText = new HelpText(
921+
new HeadingInfo(_headerInfo),
922+
_copyrightInfo)
923+
.AddPreOptionsLine("")
924+
.AddPreOptionsLine("No operation was performed with the options supplied.")
925+
.AddPreOptionsLine("")
926+
.AddPreOptionsLine(HelpText.RenderUsageText(result))
927+
.AddPreOptionsLine("")
928+
.AddOptions(result);
929+
930+
Console.WriteLine(helpText.ToString());
931+
}
926932
}
927933

928934
private static void OutputError(ExitCodes errorCode, bool outputMessage, string extraMessage = null)

nanoFirmwareFlasher/Stm32Operations.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
210210
programResult = jtagDevice.FlashBinFiles(new [] { applicationPath }, new [] { deploymentAddress });
211211
}
212212

213-
if(updateFw)
213+
if(
214+
updateFw
215+
&& programResult == ExitCodes.OK)
214216
{
215217
// reset MCU
216218
jtagDevice.ResetMcu();

0 commit comments

Comments
 (0)