From e136e367f7d0f345ca0bd8a530f7700c5af61e19 Mon Sep 17 00:00:00 2001 From: Alexander Larsen Date: Wed, 19 Jun 2024 15:03:43 +0200 Subject: [PATCH] Dont show an error message when --help is specified --- Engine/Cli/CliActionExecutor.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Engine/Cli/CliActionExecutor.cs b/Engine/Cli/CliActionExecutor.cs index 99149b028..4634355b7 100644 --- a/Engine/Cli/CliActionExecutor.cs +++ b/Engine/Cli/CliActionExecutor.cs @@ -281,10 +281,14 @@ string getVersion() } string tapCommand = OperatingSystem.Current == OperatingSystem.Windows ? "tap.exe" : "tap"; - if (args.Length != 0) + var helpOptions = new string[] { "--help", "-help", "-h" }; + bool isHelp = args.Length == 0 || args.Any(a => helpOptions.Contains(a.ToLower())); + + if (!isHelp) { log.Error($"\"{tapCommand} {string.Join(" ", args)}\" is not a recognized command."); } + log.Info("OpenTAP Command Line Interface ({0})", getVersion()); log.Info($"Usage: \"{tapCommand} [] []\"\n"); @@ -304,7 +308,7 @@ string getVersion() log.Info($"\nRun \"{tapCommand} [] -h\" to get additional help for a specific command.\n"); - if (args.Length == 0 || args.Any(s => s.ToLower() == "--help" || s.ToLower() == "-h")) + if (isHelp) return (int)ExitCodes.Success; else return (int)ExitCodes.ArgumentParseError; @@ -312,11 +316,14 @@ string getVersion() if (SelectedAction != TypeData.FromType(typeof(RunCliAction)) && UserInput.Interface == null) // RunCliAction has --non-interactive flag and custom platform interaction handling. CliUserInputInterface.Load(); - + ICliAction packageAction = null; - try{ + try + { packageAction = (ICliAction)SelectedAction.CreateInstance(); - }catch(TargetInvocationException e1) when (e1.InnerException is System.ComponentModel.LicenseException e){ + } + catch (TargetInvocationException e1) when (e1.InnerException is System.ComponentModel.LicenseException e) + { log.Error("Unable to load CLI Action '{0}'", SelectedAction.GetDisplayAttribute().GetFullName()); log.Info("{0}", e.Message); return (int)ExitCodes.UnknownCliAction;