Changing the parser description for commands that have implicit restore.

This commit is contained in:
Livar Cunha 2017-06-07 14:43:48 -07:00
parent 3231295acf
commit c89618603a
9 changed files with 225 additions and 257 deletions

View file

@ -520,4 +520,7 @@
<data name="ShowHelpDescription" xml:space="preserve"> <data name="ShowHelpDescription" xml:space="preserve">
<value>Show help information.</value> <value>Show help information.</value>
</data> </data>
<data name="NoRestoreDescription" xml:space="preserve">
<value>Does not do an implicit restore when executing the command.</value>
</data>
</root> </root>

View file

@ -0,0 +1,39 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools.MSBuild;
using Microsoft.DotNet.Tools.Restore;
namespace Microsoft.DotNet.Tools
{
public static class CreateWithRestoreOptions
{
public static Command Command(
string name,
string help,
ArgumentsRule arguments,
params Option[] options)
{
return Create.Command(name, help, arguments, RestoreCommandParser.AddImplicitRestoreOptions(options));
}
public static Command Command(
string name,
string help,
ArgumentsRule arguments,
bool treatUnmatchedTokensAsErrors,
params Option[] options)
{
return Create.Command(
name,
help,
arguments,
treatUnmatchedTokensAsErrors,
RestoreCommandParser.AddImplicitRestoreOptions(options));
}
}
}

View file

@ -14,9 +14,7 @@ namespace Microsoft.DotNet.Tools
private IEnumerable<string> ArgsToForward { get; } private IEnumerable<string> ArgsToForward { get; }
private IEnumerable<string> ArgsToForwardToRestore private IEnumerable<string> ArgsToForwardToRestore()
{
get
{ {
var restoreArguments = ArgsToForward.Where(a => var restoreArguments = ArgsToForward.Where(a =>
!a.StartsWith("/t:") && !a.StartsWith("/t:") &&
@ -31,7 +29,6 @@ namespace Microsoft.DotNet.Tools
return restoreArguments; return restoreArguments;
} }
}
private bool ShouldRunImplicitRestore => !NoRestore; private bool ShouldRunImplicitRestore => !NoRestore;
@ -46,7 +43,7 @@ namespace Microsoft.DotNet.Tools
{ {
if (ShouldRunImplicitRestore) if (ShouldRunImplicitRestore)
{ {
int exitCode = RestoreCommand.Run(ArgsToForwardToRestore.ToArray()); int exitCode = RestoreCommand.Run(ArgsToForwardToRestore().ToArray());
if (exitCode != 0) if (exitCode != 0)
{ {
return exitCode; return exitCode;

View file

@ -12,22 +12,13 @@ namespace Microsoft.DotNet.Cli
internal static class BuildCommandParser internal static class BuildCommandParser
{ {
public static Command Build() => public static Command Build() =>
Create.Command( CreateWithRestoreOptions.Command(
"build", "build",
LocalizableStrings.AppFullName, LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments() Accept.ZeroOrMoreArguments()
.With(name: CommonLocalizableStrings.CmdProjectFile, .With(name: CommonLocalizableStrings.CmdProjectFile,
description: description:
"The MSBuild project file to build. If a project file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."), "The MSBuild project file to build. If a project file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."),
FullBuildOptions
);
private static Option[] FullBuildOptions
{
get
{
var fullBuildOptions = new List<Option>
{
CommonOptions.HelpOption(), CommonOptions.HelpOption(),
Create.Option( Create.Option(
"-o|--output", "-o|--output",
@ -48,13 +39,6 @@ namespace Microsoft.DotNet.Cli
Accept.NoArguments() Accept.NoArguments()
.ForwardAs("/p:BuildProjectReferences=false")), .ForwardAs("/p:BuildProjectReferences=false")),
CommonOptions.NoRestoreOption(), CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption() CommonOptions.VerbosityOption());
};
RestoreCommandParser.AddImplicitRestoreOptions(fullBuildOptions);
return fullBuildOptions.ToArray();
}
}
} }
} }

View file

@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools;
using LocalizableStrings = Microsoft.DotNet.Tools.Pack.LocalizableStrings; using LocalizableStrings = Microsoft.DotNet.Tools.Pack.LocalizableStrings;
namespace Microsoft.DotNet.Cli namespace Microsoft.DotNet.Cli
@ -11,18 +12,10 @@ namespace Microsoft.DotNet.Cli
internal static class PackCommandParser internal static class PackCommandParser
{ {
public static Command Pack() => public static Command Pack() =>
Create.Command( CreateWithRestoreOptions.Command(
"pack", "pack",
LocalizableStrings.AppFullName, LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments(), Accept.ZeroOrMoreArguments(),
FullPackOptions);
private static Option[] FullPackOptions
{
get
{
var fullPackOptions = new List<Option>
{
CommonOptions.HelpOption(), CommonOptions.HelpOption(),
Create.Option( Create.Option(
"-o|--output", "-o|--output",
@ -49,13 +42,6 @@ namespace Microsoft.DotNet.Cli
LocalizableStrings.CmdServiceableDescription, LocalizableStrings.CmdServiceableDescription,
Accept.NoArguments().ForwardAs("/p:Serviceable=true")), Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
CommonOptions.NoRestoreOption(), CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption() CommonOptions.VerbosityOption());
};
RestoreCommandParser.AddImplicitRestoreOptions(fullPackOptions);
return fullPackOptions.ToArray();
}
}
} }
} }

View file

@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools;
using LocalizableStrings = Microsoft.DotNet.Tools.Publish.LocalizableStrings; using LocalizableStrings = Microsoft.DotNet.Tools.Publish.LocalizableStrings;
namespace Microsoft.DotNet.Cli namespace Microsoft.DotNet.Cli
@ -11,18 +12,10 @@ namespace Microsoft.DotNet.Cli
internal static class PublishCommandParser internal static class PublishCommandParser
{ {
public static Command Publish() => public static Command Publish() =>
Create.Command( CreateWithRestoreOptions.Command(
"publish", "publish",
LocalizableStrings.AppDescription, LocalizableStrings.AppDescription,
Accept.ZeroOrMoreArguments(), Accept.ZeroOrMoreArguments(),
FullPublishOptions);
private static Option[] FullPublishOptions
{
get
{
var fullPublishOptions = new List<Option>
{
CommonOptions.HelpOption(), CommonOptions.HelpOption(),
Create.Option( Create.Option(
"-o|--output", "-o|--output",
@ -51,13 +44,6 @@ namespace Microsoft.DotNet.Cli
return $"/p:SelfContained={value}"; return $"/p:SelfContained={value}";
})), })),
CommonOptions.NoRestoreOption(), CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption() CommonOptions.VerbosityOption());
};
RestoreCommandParser.AddImplicitRestoreOptions(fullPublishOptions);
return fullPublishOptions.ToArray();
}
}
} }
} }

View file

@ -15,28 +15,27 @@ namespace Microsoft.DotNet.Cli
"restore", "restore",
LocalizableStrings.AppFullName, LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments(), Accept.ZeroOrMoreArguments(),
FullRestoreOptions); FullRestoreOptions());
private static Option[] FullRestoreOptions private static Option[] FullRestoreOptions()
{ {
get var fullRestoreOptions = AddImplicitRestoreOptions(new Option[] { CommonOptions.HelpOption() }, true, true);
{
var fullRestoreOptions = new List<Option>();
fullRestoreOptions.Add(CommonOptions.HelpOption()); return fullRestoreOptions.Concat(new Option[] { CommonOptions.VerbosityOption() }).ToArray();
AddImplicitRestoreOptions(fullRestoreOptions, true, true);
fullRestoreOptions.Add(CommonOptions.VerbosityOption());
return fullRestoreOptions.ToArray();
}
} }
public static void AddImplicitRestoreOptions( public static Option[] AddImplicitRestoreOptions(
List<Option> commandOptions, IEnumerable<Option> commandOptions)
bool showHelp = false,
bool useShortOptions = false)
{ {
commandOptions.AddRange(ImplicitRestoreOptions(showHelp, useShortOptions) return AddImplicitRestoreOptions(commandOptions, false, false).ToArray();
}
private static IEnumerable<Option> AddImplicitRestoreOptions(
IEnumerable<Option> commandOptions,
bool showHelp,
bool useShortOptions)
{
return commandOptions.Concat(ImplicitRestoreOptions(showHelp, useShortOptions)
.Where(o => !commandOptions.Any(c => c.Name == o.Name))); .Where(o => !commandOptions.Any(c => c.Name == o.Name)));
} }
@ -89,11 +88,10 @@ namespace Microsoft.DotNet.Cli
Accept.NoArguments() Accept.NoArguments()
.ForwardAs("/p:RestoreRecursive=false")), .ForwardAs("/p:RestoreRecursive=false")),
Create.Option( Create.Option(
"-f|--force", useShortOptions ? "-f|--force" : "--force",
LocalizableStrings.CmdForceRestoreOptionDescription, LocalizableStrings.CmdForceRestoreOptionDescription,
Accept.NoArguments() Accept.NoArguments()
.ForwardAs("/p:RestoreForce=true")), .ForwardAs("/p:RestoreForce=true"))
CommonOptions.VerbosityOption()
}; };
} }
} }

View file

@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools;
using Microsoft.DotNet.Tools.Run; using Microsoft.DotNet.Tools.Run;
using LocalizableStrings = Microsoft.DotNet.Tools.Run.LocalizableStrings; using LocalizableStrings = Microsoft.DotNet.Tools.Run.LocalizableStrings;
@ -12,7 +13,7 @@ namespace Microsoft.DotNet.Cli
internal static class RunCommandParser internal static class RunCommandParser
{ {
public static Command Run() => public static Command Run() =>
Create.Command( CreateWithRestoreOptions.Command(
"run", "run",
LocalizableStrings.AppFullName, LocalizableStrings.AppFullName,
treatUnmatchedTokensAsErrors: false, treatUnmatchedTokensAsErrors: false,
@ -29,13 +30,7 @@ namespace Microsoft.DotNet.Cli
restoreArgs: o.OptionValuesToBeForwarded(), restoreArgs: o.OptionValuesToBeForwarded(),
args: o.Arguments args: o.Arguments
)), )),
options: FullRunOptions); options: new[]
private static Option[] FullRunOptions
{
get
{
var fullRunOptions = new List<Option>
{ {
CommonOptions.HelpOption(), CommonOptions.HelpOption(),
CommonOptions.ConfigurationOption(), CommonOptions.ConfigurationOption(),
@ -57,12 +52,6 @@ namespace Microsoft.DotNet.Cli
LocalizableStrings.CommandOptionNoBuildDescription, LocalizableStrings.CommandOptionNoBuildDescription,
Accept.NoArguments()), Accept.NoArguments()),
CommonOptions.NoRestoreOption() CommonOptions.NoRestoreOption()
}; });
RestoreCommandParser.AddImplicitRestoreOptions(fullRunOptions);
return fullRunOptions.ToArray();
}
}
} }
} }

View file

@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools;
using LocalizableStrings = Microsoft.DotNet.Tools.Test.LocalizableStrings; using LocalizableStrings = Microsoft.DotNet.Tools.Test.LocalizableStrings;
namespace Microsoft.DotNet.Cli namespace Microsoft.DotNet.Cli
@ -18,14 +19,6 @@ namespace Microsoft.DotNet.Cli
.With(name: LocalizableStrings.CmdArgProject, .With(name: LocalizableStrings.CmdArgProject,
description: LocalizableStrings.CmdArgDescription), description: LocalizableStrings.CmdArgDescription),
false, false,
FullTestOptions);
private static Option[] FullTestOptions
{
get
{
var fullTestOptions = new List<Option>
{
CommonOptions.HelpOption(), CommonOptions.HelpOption(),
Create.Option( Create.Option(
"-s|--settings", "-s|--settings",
@ -93,14 +86,7 @@ namespace Microsoft.DotNet.Cli
.With(name: LocalizableStrings.cmdCollectFriendlyName) .With(name: LocalizableStrings.cmdCollectFriendlyName)
.ForwardAsSingle(o => $"/p:VSTestCollect=\"{string.Join(";", o.Arguments)}\"")), .ForwardAsSingle(o => $"/p:VSTestCollect=\"{string.Join(";", o.Arguments)}\"")),
CommonOptions.NoRestoreOption(), CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption() CommonOptions.VerbosityOption());
};
RestoreCommandParser.AddImplicitRestoreOptions(fullTestOptions);
return fullTestOptions.ToArray();
}
}
private static string GetSemiColonEsacpedstring(string arg) private static string GetSemiColonEsacpedstring(string arg)
{ {