Skip to content

Commit 527e3d0

Browse files
authored
Fix output of device operations (#249)
1 parent 349928d commit 527e3d0

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

nanoFirmwareFlasher.Tool/NanoDeviceManager.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public NanoDeviceManager(Options options, VerbosityLevel verbosityLevel)
2929
/// <inheritdoc />
3030
public async Task<ExitCodes> ProcessAsync()
3131
{
32+
bool failedToDoSomething = true;
33+
ExitCodes exitCode = ExitCodes.OK;
34+
3235
// COM port is mandatory for nano device operations
3336
if (string.IsNullOrEmpty(_options.SerialPort))
3437
{
@@ -46,7 +49,7 @@ public async Task<ExitCodes> ProcessAsync()
4649
}
4750
else if (_options.Update)
4851
{
49-
var exitCode = await _nanoDeviceOperations.UpdateDeviceClrAsync(
52+
exitCode = await _nanoDeviceOperations.UpdateDeviceClrAsync(
5053
_options.SerialPort,
5154
_options.FwVersion,
5255
_options.ClrFile,
@@ -56,11 +59,14 @@ public async Task<ExitCodes> ProcessAsync()
5659
{
5760
return exitCode;
5861
}
62+
63+
// flag operation as done
64+
failedToDoSomething = false;
5965
}
6066

6167
if (_options.Deploy)
6268
{
63-
var exitCode = _nanoDeviceOperations.DeployApplication(
69+
exitCode = _nanoDeviceOperations.DeployApplication(
6470
_options.SerialPort,
6571
_options.DeploymentImage,
6672
_verbosityLevel);
@@ -69,9 +75,17 @@ public async Task<ExitCodes> ProcessAsync()
6975
{
7076
return exitCode;
7177
}
78+
79+
// flag operation as done
80+
failedToDoSomething = false;
81+
}
82+
83+
if (failedToDoSomething)
84+
{
85+
throw new NoOperationPerformedException();
7286
}
7387

74-
throw new NoOperationPerformedException();
88+
return exitCode;
7589
}
7690
}
7791
}

nanoFirmwareFlasher.Tool/Program.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -364,30 +364,32 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
364364
{
365365
var manager = new NanoDeviceManager(o, _verbosityLevel);
366366

367-
try
368-
{
369-
_exitCode = await manager.ProcessAsync();
370-
}
371-
catch (CantConnectToNanoDeviceException ex)
372-
{
373-
_exitCode = ExitCodes.E2001;
374-
_extraMessage = ex.Message;
375-
}
376-
catch (NoOperationPerformedException)
377-
{
378-
DisplayNoOperationMessage();
379-
}
380-
catch (Exception ex)
381-
{
382-
_exitCode = ExitCodes.E2002;
383-
_extraMessage = ex.Message;
384-
}
385-
386367
// COM port is mandatory for nano device operations
387368
if (string.IsNullOrEmpty(o.SerialPort))
388369
{
389370
_exitCode = ExitCodes.E6001;
390371
}
372+
else
373+
{
374+
try
375+
{
376+
_exitCode = await manager.ProcessAsync();
377+
}
378+
catch (CantConnectToNanoDeviceException ex)
379+
{
380+
_exitCode = ExitCodes.E2001;
381+
_extraMessage = ex.Message;
382+
}
383+
catch (NoOperationPerformedException)
384+
{
385+
DisplayNoOperationMessage();
386+
}
387+
catch (Exception ex)
388+
{
389+
_exitCode = ExitCodes.E2002;
390+
_extraMessage = ex.Message;
391+
}
392+
}
391393

392394
return;
393395
}

0 commit comments

Comments
 (0)