System.CommandLine uses Environment.FailFast when help or ReportError is detected. This causes the debugger to get invoked in windows and is not desirable. The fix here is to handle error and help ourselves, but still use the getHelpText from System.CommandLine to generate the help content.
This commit is contained in:
parent
e764896edb
commit
82cdb28970
4 changed files with 57 additions and 5 deletions
|
@ -32,11 +32,17 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
|
||||||
IReadOnlyList<string> resources = Array.Empty<string>();
|
IReadOnlyList<string> resources = Array.Empty<string>();
|
||||||
IReadOnlyList<string> sources = Array.Empty<string>();
|
IReadOnlyList<string> sources = Array.Empty<string>();
|
||||||
string outputName = null;
|
string outputName = null;
|
||||||
|
var help = false;
|
||||||
|
var returnCode = 0;
|
||||||
|
string helpText = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ArgumentSyntax.Parse(args, syntax =>
|
ArgumentSyntax.Parse(args, syntax =>
|
||||||
{
|
{
|
||||||
|
syntax.HandleHelp = false;
|
||||||
|
syntax.HandleErrors = false;
|
||||||
|
|
||||||
commonOptions = CommonCompilerOptionsExtensions.Parse(syntax);
|
commonOptions = CommonCompilerOptionsExtensions.Parse(syntax);
|
||||||
|
|
||||||
assemblyInfoOptions = AssemblyInfoOptions.Parse(syntax);
|
assemblyInfoOptions = AssemblyInfoOptions.Parse(syntax);
|
||||||
|
@ -49,16 +55,30 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
|
||||||
|
|
||||||
syntax.DefineOptionList("resource", ref resources, "Resources to embed");
|
syntax.DefineOptionList("resource", ref resources, "Resources to embed");
|
||||||
|
|
||||||
|
syntax.DefineOption("h|help", ref help, "Help for compile native.");
|
||||||
|
|
||||||
syntax.DefineParameterList("source-files", ref sources, "Compilation sources");
|
syntax.DefineParameterList("source-files", ref sources, "Compilation sources");
|
||||||
|
|
||||||
|
helpText = syntax.GetHelpText();
|
||||||
|
|
||||||
if (tempOutDir == null)
|
if (tempOutDir == null)
|
||||||
{
|
{
|
||||||
syntax.ReportError("Option '--temp-output' is required");
|
syntax.ReportError("Option '--temp-output' is required");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (ArgumentSyntaxException)
|
catch (ArgumentSyntaxException exception)
|
||||||
{
|
{
|
||||||
return ExitFailed;
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
help = true;
|
||||||
|
returnCode = ExitFailed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (help)
|
||||||
|
{
|
||||||
|
Console.WriteLine(helpText);
|
||||||
|
|
||||||
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
var translated = TranslateCommonOptions(commonOptions);
|
var translated = TranslateCommonOptions(commonOptions);
|
||||||
|
|
|
@ -17,6 +17,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
public string AppDepSDKPath { get; set; }
|
public string AppDepSDKPath { get; set; }
|
||||||
public string IlcPath { get; set; }
|
public string IlcPath { get; set; }
|
||||||
|
|
||||||
|
public bool IsHelp { get; set; }
|
||||||
|
public int ReturnCode { get; set; }
|
||||||
|
|
||||||
public NativeCompileSettings GetNativeCompileSettings()
|
public NativeCompileSettings GetNativeCompileSettings()
|
||||||
{
|
{
|
||||||
var config = NativeCompileSettings.Default;
|
var config = NativeCompileSettings.Default;
|
||||||
|
|
|
@ -19,14 +19,20 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
string ilcPath = null;
|
string ilcPath = null;
|
||||||
string appDepSdk = null;
|
string appDepSdk = null;
|
||||||
string logPath = null;
|
string logPath = null;
|
||||||
|
var help = false;
|
||||||
|
string helpText = null;
|
||||||
|
var returnCode = 0;
|
||||||
|
|
||||||
IReadOnlyList<string> references = Array.Empty<string>();
|
IReadOnlyList<string> references = Array.Empty<string>();
|
||||||
IReadOnlyList<string> linklib = Array.Empty<string>();
|
IReadOnlyList<string> linklib = Array.Empty<string>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ArgumentSyntax.Parse(args, syntax =>
|
ArgumentSyntax.Parse(args, syntax =>
|
||||||
{
|
{
|
||||||
|
syntax.HandleHelp = false;
|
||||||
|
syntax.HandleErrors = false;
|
||||||
|
|
||||||
syntax.DefineOption("output", ref outputDirectory, "Output Directory for native executable.");
|
syntax.DefineOption("output", ref outputDirectory, "Output Directory for native executable.");
|
||||||
syntax.DefineOption("temp-output", ref temporaryOutputDirectory, "Directory for intermediate files.");
|
syntax.DefineOption("temp-output", ref temporaryOutputDirectory, "Directory for intermediate files.");
|
||||||
|
|
||||||
|
@ -48,12 +54,17 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
// Optional Log Path
|
// Optional Log Path
|
||||||
syntax.DefineOption("logpath", ref logPath, "Use to dump Native Compilation Logs to a file.");
|
syntax.DefineOption("logpath", ref logPath, "Use to dump Native Compilation Logs to a file.");
|
||||||
|
|
||||||
|
syntax.DefineOption("h|help", ref help, "Help for compile native.");
|
||||||
|
|
||||||
syntax.DefineParameter("INPUT_ASSEMBLY", ref inputAssembly,
|
syntax.DefineParameter("INPUT_ASSEMBLY", ref inputAssembly,
|
||||||
"The managed input assembly to compile to native.");
|
"The managed input assembly to compile to native.");
|
||||||
|
|
||||||
|
helpText = syntax.GetHelpText();
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(inputAssembly))
|
if (string.IsNullOrWhiteSpace(inputAssembly))
|
||||||
{
|
{
|
||||||
syntax.ReportError("Input Assembly is a required parameter.");
|
syntax.ReportError("Input Assembly is a required parameter.");
|
||||||
|
help = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(configuration))
|
if (!string.IsNullOrEmpty(configuration))
|
||||||
|
@ -65,6 +76,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
syntax.ReportError($"Invalid Configuration Option: {configuration}");
|
syntax.ReportError($"Invalid Configuration Option: {configuration}");
|
||||||
|
help = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,13 +89,27 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
syntax.ReportError($"Invalid Mode Option: {mode}");
|
syntax.ReportError($"Invalid Mode Option: {mode}");
|
||||||
|
help = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (ArgumentSyntaxException)
|
catch (ArgumentSyntaxException exception)
|
||||||
{
|
{
|
||||||
//return ExitFailed;
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
help = true;
|
||||||
|
returnCode = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (help)
|
||||||
|
{
|
||||||
|
Console.WriteLine(helpText);
|
||||||
|
|
||||||
|
return new ArgValues
|
||||||
|
{
|
||||||
|
IsHelp = help,
|
||||||
|
ReturnCode = returnCode
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"Input Assembly: {inputAssembly}");
|
Console.WriteLine($"Input Assembly: {inputAssembly}");
|
||||||
|
|
|
@ -32,6 +32,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var cmdLineArgs = ArgumentsParser.Parse(args);
|
var cmdLineArgs = ArgumentsParser.Parse(args);
|
||||||
|
|
||||||
|
if (cmdLineArgs.IsHelp) return cmdLineArgs.ReturnCode;
|
||||||
|
|
||||||
var config = cmdLineArgs.GetNativeCompileSettings();
|
var config = cmdLineArgs.GetNativeCompileSettings();
|
||||||
|
|
||||||
DirectoryExtensions.CleanOrCreateDirectory(config.OutputDirectory);
|
DirectoryExtensions.CleanOrCreateDirectory(config.OutputDirectory);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue