Fixing compiler command line options bugs.
- Ensure the long names start with `--` - Handle null strings in UnescapeNewlines - Handle bool options correctly. - Allow dotnet run, compile-csc, and compile-fsc to handle .rsp files.
This commit is contained in:
parent
6fa3a8132e
commit
02194fca67
5 changed files with 53 additions and 44 deletions
|
@ -27,6 +27,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Fsc
|
|||
app.Name = "dotnet compile-fsc";
|
||||
app.FullName = ".NET F# Compiler";
|
||||
app.Description = "F# Compiler for the .NET Platform";
|
||||
app.HandleResponseFiles = true;
|
||||
app.HelpOption("-h|--help");
|
||||
|
||||
CommonCompilerOptionsCommandLine commonCompilerCommandLine = CommonCompilerOptionsCommandLine.AddOptions(app);
|
||||
|
|
|
@ -9,8 +9,6 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
{
|
||||
internal class AssemblyInfoOptionsCommandLine
|
||||
{
|
||||
private const string ArgTemplate = "<arg>";
|
||||
|
||||
public CommandOption VersionOption { get; set; }
|
||||
public CommandOption TitleOption { get; set; }
|
||||
public CommandOption DescriptionOption { get; set; }
|
||||
|
@ -25,36 +23,32 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
{
|
||||
AssemblyInfoOptionsCommandLine commandLineOptions = new AssemblyInfoOptionsCommandLine();
|
||||
|
||||
commandLineOptions.VersionOption =
|
||||
app.Option($"{AssemblyVersionOptionName} {ArgTemplate}", "Assembly version", CommandOptionType.SingleValue);
|
||||
commandLineOptions.VersionOption = AddOption(app, AssemblyVersionOptionName, "Assembly version");
|
||||
|
||||
commandLineOptions.TitleOption =
|
||||
app.Option($"{TitleOptionName} {ArgTemplate}", "Assembly title", CommandOptionType.SingleValue);
|
||||
commandLineOptions.TitleOption = AddOption(app, TitleOptionName, "Assembly title");
|
||||
|
||||
commandLineOptions.DescriptionOption =
|
||||
app.Option($"{DescriptionOptionName} {ArgTemplate}", "Assembly description", CommandOptionType.SingleValue);
|
||||
commandLineOptions.DescriptionOption = AddOption(app, DescriptionOptionName, "Assembly description");
|
||||
|
||||
commandLineOptions.CopyrightOption =
|
||||
app.Option($"{CopyrightOptionName} {ArgTemplate}", "Assembly copyright", CommandOptionType.SingleValue);
|
||||
commandLineOptions.CopyrightOption = AddOption(app, CopyrightOptionName, "Assembly copyright");
|
||||
|
||||
commandLineOptions.NeutralCultureOption =
|
||||
app.Option($"{NeutralCultureOptionName} {ArgTemplate}", "Assembly neutral culture", CommandOptionType.SingleValue);
|
||||
commandLineOptions.NeutralCultureOption = AddOption(app, NeutralCultureOptionName, "Assembly neutral culture");
|
||||
|
||||
commandLineOptions.CultureOption =
|
||||
app.Option($"{CultureOptionName} {ArgTemplate}", "Assembly culture", CommandOptionType.SingleValue);
|
||||
commandLineOptions.CultureOption = AddOption(app, CultureOptionName, "Assembly culture");
|
||||
|
||||
commandLineOptions.InformationalVersionOption =
|
||||
app.Option($"{InformationalVersionOptionName} {ArgTemplate}", "Assembly informational version", CommandOptionType.SingleValue);
|
||||
commandLineOptions.InformationalVersionOption = AddOption(app, InformationalVersionOptionName, "Assembly informational version");
|
||||
|
||||
commandLineOptions.FileVersionOption =
|
||||
app.Option($"{AssemblyFileVersionOptionName} {ArgTemplate}", "Assembly file version", CommandOptionType.SingleValue);
|
||||
commandLineOptions.FileVersionOption = AddOption(app, AssemblyFileVersionOptionName, "Assembly file version");
|
||||
|
||||
commandLineOptions.TargetFrameworkOption =
|
||||
app.Option($"{TargetFrameworkOptionName} {ArgTemplate}", "Assembly target framework", CommandOptionType.SingleValue);
|
||||
commandLineOptions.TargetFrameworkOption = AddOption(app, TargetFrameworkOptionName, "Assembly target framework");
|
||||
|
||||
return commandLineOptions;
|
||||
}
|
||||
|
||||
private static CommandOption AddOption(CommandLineApplication app, string optionName, string description)
|
||||
{
|
||||
return app.Option($"--{optionName} <arg>", description, CommandOptionType.SingleValue);
|
||||
}
|
||||
|
||||
public AssemblyInfoOptions GetOptionValues()
|
||||
{
|
||||
return new AssemblyInfoOptions()
|
||||
|
@ -73,6 +67,11 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
private static string UnescapeNewlines(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
return text.Replace("\\r", "\r").Replace("\\n", "\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
{
|
||||
internal class CommonCompilerOptionsCommandLine
|
||||
{
|
||||
private const string ArgTemplate = "<arg>";
|
||||
|
||||
public CommandOption DefineOption { get; set; }
|
||||
public CommandOption SuppressWarningOption { get; set; }
|
||||
public CommandOption LanguageVersionOption { get; set; }
|
||||
|
@ -32,53 +30,61 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
CommonCompilerOptionsCommandLine commandLineOptions = new CommonCompilerOptionsCommandLine();
|
||||
|
||||
commandLineOptions.DefineOption =
|
||||
app.Option($"{DefineOptionName} {ArgTemplate}...", "Preprocessor definitions", CommandOptionType.MultipleValue);
|
||||
AddOption(app, DefineOptionName, "Preprocessor definitions", CommandOptionType.MultipleValue);
|
||||
|
||||
commandLineOptions.SuppressWarningOption =
|
||||
app.Option($"{SuppressWarningOptionName} {ArgTemplate}...", "Suppresses the specified warning", CommandOptionType.MultipleValue);
|
||||
AddOption(app, SuppressWarningOptionName, "Suppresses the specified warning", CommandOptionType.MultipleValue);
|
||||
|
||||
commandLineOptions.LanguageVersionOption =
|
||||
app.Option($"{LanguageVersionOptionName} {ArgTemplate}", "The version of the language used to compile", CommandOptionType.SingleValue);
|
||||
AddOption(app, LanguageVersionOptionName, "The version of the language used to compile", CommandOptionType.SingleValue);
|
||||
|
||||
commandLineOptions.PlatformOption =
|
||||
app.Option($"{PlatformOptionName} {ArgTemplate}", "The target platform", CommandOptionType.SingleValue);
|
||||
AddOption(app, PlatformOptionName, "The target platform", CommandOptionType.SingleValue);
|
||||
|
||||
commandLineOptions.AllowUnsafeOption =
|
||||
app.Option($"{AllowUnsafeOptionName} {ArgTemplate}", "Allow unsafe code", CommandOptionType.SingleValue);
|
||||
AddOption(app, AllowUnsafeOptionName, "Allow unsafe code", CommandOptionType.BoolValue);
|
||||
|
||||
commandLineOptions.WarningsAsErrorsOption =
|
||||
app.Option($"{WarningsAsErrorsOptionName} {ArgTemplate}", "Turn all warnings into errors", CommandOptionType.SingleValue);
|
||||
AddOption(app, WarningsAsErrorsOptionName, "Turn all warnings into errors", CommandOptionType.BoolValue);
|
||||
|
||||
commandLineOptions.OptimizeOption =
|
||||
app.Option($"{OptimizeOptionName} {ArgTemplate}", "Enable compiler optimizations", CommandOptionType.SingleValue);
|
||||
AddOption(app, OptimizeOptionName, "Enable compiler optimizations", CommandOptionType.BoolValue);
|
||||
|
||||
commandLineOptions.KeyFileOption =
|
||||
app.Option($"{KeyFileOptionName} {ArgTemplate}", "Path to file containing the key to strong-name sign the output assembly", CommandOptionType.SingleValue);
|
||||
AddOption(app, KeyFileOptionName, "Path to file containing the key to strong-name sign the output assembly", CommandOptionType.SingleValue);
|
||||
|
||||
commandLineOptions.DelaySignOption =
|
||||
app.Option($"{DelaySignOptionName} {ArgTemplate}", "Delay-sign the output assembly", CommandOptionType.SingleValue);
|
||||
AddOption(app, DelaySignOptionName, "Delay-sign the output assembly", CommandOptionType.BoolValue);
|
||||
|
||||
commandLineOptions.PublicSignOption =
|
||||
app.Option($"{PublicSignOptionName} {ArgTemplate}", "Public-sign the output assembly", CommandOptionType.SingleValue);
|
||||
AddOption(app, PublicSignOptionName, "Public-sign the output assembly", CommandOptionType.BoolValue);
|
||||
|
||||
commandLineOptions.DebugTypeOption =
|
||||
app.Option($"{DebugTypeOptionName} {ArgTemplate}", "The type of PDB to emit: portable or full", CommandOptionType.SingleValue);
|
||||
AddOption(app, DebugTypeOptionName, "The type of PDB to emit: portable or full", CommandOptionType.SingleValue);
|
||||
|
||||
commandLineOptions.EmitEntryPointOption =
|
||||
app.Option($"{EmitEntryPointOptionName} {ArgTemplate}", "Output an executable console program", CommandOptionType.SingleValue);
|
||||
AddOption(app, EmitEntryPointOptionName, "Output an executable console program", CommandOptionType.BoolValue);
|
||||
|
||||
commandLineOptions.GenerateXmlDocumentationOption =
|
||||
app.Option($"{GenerateXmlDocumentationOptionName} {ArgTemplate}", "Generate XML documentation file", CommandOptionType.SingleValue);
|
||||
AddOption(app, GenerateXmlDocumentationOptionName, "Generate XML documentation file", CommandOptionType.BoolValue);
|
||||
|
||||
commandLineOptions.AdditionalArgumentsOption =
|
||||
app.Option($"{AdditionalArgumentsOptionName} {ArgTemplate}...", "Pass the additional argument directly to the compiler", CommandOptionType.MultipleValue);
|
||||
AddOption(app, AdditionalArgumentsOptionName, "Pass the additional argument directly to the compiler", CommandOptionType.MultipleValue);
|
||||
|
||||
commandLineOptions.OutputNameOption =
|
||||
app.Option($"{OutputNameOptionName} {ArgTemplate}", "Output assembly name", CommandOptionType.SingleValue);
|
||||
AddOption(app, OutputNameOptionName, "Output assembly name", CommandOptionType.SingleValue);
|
||||
|
||||
return commandLineOptions;
|
||||
}
|
||||
|
||||
private static CommandOption AddOption(CommandLineApplication app, string optionName, string description, CommandOptionType optionType)
|
||||
{
|
||||
string argSuffix = optionType == CommandOptionType.MultipleValue ? "..." : null;
|
||||
string argString = optionType == CommandOptionType.BoolValue ? null : $" <arg>{argSuffix}";
|
||||
|
||||
return app.Option($"--{optionName}{argString}", description, optionType);
|
||||
}
|
||||
|
||||
public CommonCompilerOptions GetOptionValues()
|
||||
{
|
||||
return new CommonCompilerOptions()
|
||||
|
@ -87,15 +93,15 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
SuppressWarnings = SuppressWarningOption.Values,
|
||||
LanguageVersion = LanguageVersionOption.Value(),
|
||||
Platform = PlatformOption.Value(),
|
||||
AllowUnsafe = bool.Parse(AllowUnsafeOption.Value()),
|
||||
WarningsAsErrors = bool.Parse(WarningsAsErrorsOption.Value()),
|
||||
Optimize = bool.Parse(OptimizeOption.Value()),
|
||||
AllowUnsafe = AllowUnsafeOption.BoolValue,
|
||||
WarningsAsErrors = WarningsAsErrorsOption.BoolValue,
|
||||
Optimize = OptimizeOption.BoolValue,
|
||||
KeyFile = KeyFileOption.Value(),
|
||||
DelaySign = bool.Parse(DelaySignOption.Value()),
|
||||
PublicSign = bool.Parse(PublicSignOption.Value()),
|
||||
DelaySign = DelaySignOption.BoolValue,
|
||||
PublicSign = PublicSignOption.BoolValue,
|
||||
DebugType = DebugTypeOption.Value(),
|
||||
EmitEntryPoint = bool.Parse(EmitEntryPointOption.Value()),
|
||||
GenerateXmlDocumentation = bool.Parse(GenerateXmlDocumentationOption.Value()),
|
||||
EmitEntryPoint = EmitEntryPointOption.BoolValue,
|
||||
GenerateXmlDocumentation = GenerateXmlDocumentationOption.BoolValue,
|
||||
AdditionalArguments = AdditionalArgumentsOption.Values,
|
||||
OutputName = OutputNameOption.Value(),
|
||||
};
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
|
|||
app.Name = "dotnet compile-csc";
|
||||
app.FullName = ".NET C# Compiler";
|
||||
app.Description = "C# Compiler for the .NET Platform";
|
||||
app.HandleResponseFiles = true;
|
||||
app.HelpOption("-h|--help");
|
||||
|
||||
CommonCompilerOptionsCommandLine commonCompilerCommandLine = CommonCompilerOptionsCommandLine.AddOptions(app);
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
app.Name = "dotnet run";
|
||||
app.FullName = ".NET Run Command";
|
||||
app.Description = "Command used to run .NET apps";
|
||||
app.HandleResponseFiles = true;
|
||||
app.HelpOption("-h|--help");
|
||||
|
||||
CommandOption framework = app.Option("-f|--framework", "Compile a specific framework", CommandOptionType.SingleValue);
|
||||
|
@ -38,6 +39,7 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
|
||||
return runCmd.Start();
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
return app.Execute(args);
|
||||
|
|
Loading…
Add table
Reference in a new issue