Skip to content

Commit

Permalink
Add "sanity checks" for incompatible and/or nonsense options (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes committed May 31, 2024
1 parent b1fb1ba commit 18c31ba
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions nanoFirmwareFlasher.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,15 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)

if (o.NanoDevice)
{
// check for invalid options passed with nano device operations
if (o.Platform.HasValue
|| !string.IsNullOrEmpty(o.TargetName))
{
_exitCode = ExitCodes.E9000;
_extraMessage = "Incompatible options combined with --nanodevice.";
return;
}

var manager = new NanoDeviceManager(o, _verbosityLevel);

// COM port is mandatory for nano device operations
Expand Down Expand Up @@ -412,8 +421,16 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)

// if a target name was specified, try to be smart and set the platform accordingly (in case it wasn't specified)
if (o.Platform == null
&& !string.IsNullOrEmpty(o.TargetName))
&& !string.IsNullOrEmpty(o.TargetName))
{
// check for invalid options passed with platform option
if (o.NanoDevice)
{
_exitCode = ExitCodes.E9000;
_extraMessage = "Incompatible options combined with --platform.";
return;
}

// easiest one: ESP32
if (o.TargetName.StartsWith("ESP")
|| o.TargetName.StartsWith("M5")
Expand Down Expand Up @@ -496,7 +513,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
}
// ESP32 related
else if (
!string.IsNullOrEmpty(o.SerialPort) &&
!string.IsNullOrEmpty(o.SerialPort) &&
((o.BaudRate != 921600) ||
(o.Esp32FlashMode != "dio") ||
(o.Esp32FlashFrequency != 40)))
Expand Down

0 comments on commit 18c31ba

Please sign in to comment.