diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index 8667b5f76..cfc1c1c70 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Cli public static Option VerbosityOption() => Create.Option( "-v|--verbosity", - "Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]", + "Set the verbosity level of the command. Allowed values are q[uiet],�m[inimal],�n[ormal],�d[etailed], and�diag[nostic]", Accept.AnyOneOf( "q", "quiet", "m", "minimal", @@ -25,6 +25,33 @@ namespace Microsoft.DotNet.Cli "d", "detailed", "diag", "diagnostic") .ForwardAs(o => $"/verbosity:{o.Arguments.Single()}")); + + public static Option FrameworkOption() => + Create.Option( + "-f|--framework", + "Target framework to publish for. The target framework has to be specified in the project file.", + Accept.ExactlyOneArgument + .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) + .With(name: "FRAMEWORK") + .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")); + + public static Option RuntimeOption() => + Create.Option( + "-r|--runtime", + "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", + Accept.ExactlyOneArgument + .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) + .With(name: "RUNTIME_IDENTIFIER") + .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")); + + public static Option ConfigurationOption() => + Create.Option( + "-c|--configuration", + "Configuration to use for building the project. Default for most projects is \"Debug\".", + Accept.ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom("DEBUG", "RELEASE") + .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index e00ed76eb..8394ce441 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -20,23 +20,9 @@ namespace Microsoft.DotNet.Cli Accept.ExactlyOneArgument .With(name: "OUTPUT_DIR") .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), - Create.Option( - "-f|--framework", - "Target framework to build for. The target framework has to be specified in the project file.", - Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) - .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")), - Create.Option( - "-r|--runtime", - "Target runtime to build for. The default is to build a portable application.", - Accept.AnyOneOf(Suggest.RunTimesFromProjectFile) - .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")), - Create.Option( - "-c|--configuration", - "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", "RELEASE") - .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), + CommonOptions.FrameworkOption(), + CommonOptions.RuntimeOption(), + CommonOptions.ConfigurationOption(), Create.Option( "--version-suffix", "Defines the value for the $(VersionSuffix) property in the project", diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index 4aae155ce..895ea919b 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -14,28 +14,14 @@ namespace Microsoft.DotNet.Cli ".NET Publisher", Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), - Create.Option("-f|--framework", - "Target framework to publish for. The target framework has to be specified in the project file.", - Accept.ExactlyOneArgument - .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) - .With(name: "FRAMEWORK") - .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")), - Create.Option("-r|--runtime", - "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", - Accept.ExactlyOneArgument - .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) - .With(name: "RUNTIME_IDENTIFIER") - .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")), + CommonOptions.FrameworkOption(), + CommonOptions.RuntimeOption(), Create.Option("-o|--output", "Output directory in which to place the published artifacts.", Accept.ExactlyOneArgument .With(name: "OUTPUT_DIR") .ForwardAs(o => $"/p:PublishDir={o.Arguments.Single()}")), - Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", "RELEASE") - .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), + CommonOptions.ConfigurationOption(), Create.Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", Accept.ExactlyOneArgument .With(name: "VERSION_SUFFIX")