This commit is contained in:
Piotr Puszkiewicz 2016-12-04 23:24:07 -08:00
parent 29b824a6ff
commit 82ec742d37
4 changed files with 59 additions and 24 deletions

View file

@ -0,0 +1,25 @@
namespace Microsoft.DotNet.Tools.Add
{
internal class LocalizableStrings
{
public const string NetAddCommand = ".NET Add Command";
public const string Usage = "Usage";
public const string Options = "Options";
public const string HelpDefinition = "Show help information";
public const string Arguments = "Arguments";
public const string ArgumentsObjectDefinition = "The object of the operation. If a project file is not specified, it defaults to the current directory.";
public const string ArgumentsCommandDefinition = "Command to be executed on <object>.";
public const string ArgsDefinition = "Any extra arguments passed to the command. Use `dotnet add <command> --help` to get help about these arguments.";
public const string Commands = "Commands";
public const string CommandP2PDefinition = "Add project to project (p2p) reference to a project";
}
}

View file

@ -16,22 +16,22 @@ namespace Microsoft.DotNet.Tools.Add
{ {
public class AddCommand : DispatchCommand public class AddCommand : DispatchCommand
{ {
protected override string HelpText => @".NET Add Command protected override string HelpText => $@"{LocalizableStrings.NetAddCommand}
Usage: dotnet add [options] <object> <command> [[--] <arg>...]] {LocalizableStrings.Usage}: dotnet add [options] <object> <command> [[--] <arg>...]]
Options: {LocalizableStrings.Options}:
-h|--help Show help information -h|--help {LocalizableStrings.HelpDefinition}
Arguments: {LocalizableStrings.Arguments}:
<object> The object of the operation. If a project file is not specified, it defaults to the current directory. <object> {LocalizableStrings.ArgumentsObjectDefinition}
<command> Command to be executed on <object>. <command> {LocalizableStrings.ArgumentsCommandDefinition}
Args: Args:
Any extra arguments passed to the command. Use `dotnet add <command> --help` to get help about these arguments. {LocalizableStrings.ArgsDefinition}
Commands: {LocalizableStrings.Commands}:
p2p Add project to project (p2p) reference to a project"; p2p {LocalizableStrings.CommandP2PDefinition}";
protected override Dictionary<string, Func<string[], int>> BuiltInCommands => new Dictionary<string, Func<string[], int>> protected override Dictionary<string, Func<string[], int>> BuiltInCommands => new Dictionary<string, Func<string[], int>>
{ {

View file

@ -2,10 +2,22 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
{ {
internal class LocalizableStrings internal class LocalizableStrings
{ {
public const string ReferenceIsInvalid = "Reference `{0}` is invalid."; public const string AppFullName = ".NET Add Project to Project (p2p) reference Command";
public const string SpecifyAtLeastOneReferenceToAdd = "You must specify at least one reference to add. Please run dotnet add --help for more information."; public const string AppDescription = "Command to add project to project (p2p) reference";
public const string ProjectAlreadyHasAReference = "Project {0} already has a reference `{1}`."; public const string AppHelpText = "Project to project references to add";
public const string CmdProject = "PROJECT";
public const string CmdProjectDescription = "The project file to modify. If a project file is not specified, it searches the current working directory for an MSBuild file that has a file extension that ends in `proj` and uses that file.";
public const string CmdFramework = "FRAMEWORK";
public const string CmdFrameworkDescription = "Add reference only when targetting a specific framework";
public const string CmdForceDescription = "Add reference even if it does not exist, do not convert paths to relative";
public const string ProjectException = "Project";
} }
} }

View file

@ -16,34 +16,32 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false) CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false)
{ {
Name = "dotnet add p2p", Name = "dotnet add p2p",
FullName = ".NET Add Project to Project (p2p) reference Command", FullName = LocalizableStrings.AppFullName,
Description = "Command to add project to project (p2p) reference", Description = LocalizableStrings.AppDescription,
AllowArgumentSeparator = true, AllowArgumentSeparator = true,
ArgumentSeparatorHelpText = "Project to project references to add" ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText
}; };
app.HelpOption("-h|--help"); app.HelpOption("-h|--help");
CommandArgument projectArgument = app.Argument( CommandArgument projectArgument = app.Argument(
"<PROJECT>", $"<{LocalizableStrings.CmdProject}>",
"The project file to modify. If a project file is not specified," + LocalizableStrings.CmdProjectDescription);
" it searches the current working directory for an MSBuild file that has" +
" a file extension that ends in `proj` and uses that file.");
CommandOption frameworkOption = app.Option( CommandOption frameworkOption = app.Option(
"-f|--framework <FRAMEWORK>", $"-f|--framework <{LocalizableStrings.CmdFramework}>",
"Add reference only when targetting a specific framework", LocalizableStrings.CmdFrameworkDescription,
CommandOptionType.SingleValue); CommandOptionType.SingleValue);
CommandOption forceOption = app.Option( CommandOption forceOption = app.Option(
"--force", "--force",
"Add reference even if it does not exist, do not convert paths to relative", LocalizableStrings.CmdForceDescription,
CommandOptionType.NoValue); CommandOptionType.NoValue);
app.OnExecute(() => { app.OnExecute(() => {
if (string.IsNullOrEmpty(projectArgument.Value)) if (string.IsNullOrEmpty(projectArgument.Value))
{ {
throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, "<Project>"); throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, $"<{LocalizableStrings.ProjectException}>");
} }
var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value); var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value);