Strings->LocalizableStrings, Extensions->ProjectRootElementExtensions, fix long lines, remove empty line

This commit is contained in:
Krzysztof Wicher 2016-11-23 15:35:01 -08:00
parent 93c30898e4
commit 8b565616a0
5 changed files with 41 additions and 24 deletions

View file

@ -4,7 +4,7 @@ using System.Text;
namespace Microsoft.DotNet.Tools namespace Microsoft.DotNet.Tools
{ {
internal static class Strings internal static class LocalizableStrings
{ {
// Arguments parsing // Arguments parsing
public const string RequiredArgumentNotPassed = "Required argument {0} was not passed."; public const string RequiredArgumentNotPassed = "Required argument {0} was not passed.";

View file

@ -49,7 +49,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
app.OnExecute(() => { app.OnExecute(() => {
if (string.IsNullOrEmpty(projectArgument.Value)) if (string.IsNullOrEmpty(projectArgument.Value))
{ {
throw new GracefulException(Strings.RequiredArgumentNotPassed, "<Project>"); throw new GracefulException(LocalizableStrings.RequiredArgumentNotPassed, "<Project>");
} }
ProjectRootElement project; ProjectRootElement project;
@ -69,7 +69,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
if (app.RemainingArguments.Count == 0) if (app.RemainingArguments.Count == 0)
{ {
throw new GracefulException(Strings.SpecifyAtLeastOneReference); throw new GracefulException(LocalizableStrings.SpecifyAtLeastOneReference);
} }
List<string> references = app.RemainingArguments; List<string> references = app.RemainingArguments;
@ -120,7 +120,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
throw new GracefulException( throw new GracefulException(
string.Join( string.Join(
Environment.NewLine, Environment.NewLine,
notExisting.Select((r) => string.Format(Strings.ReferenceDoesNotExist, r)))); notExisting.Select((r) => string.Format(LocalizableStrings.ReferenceDoesNotExist, r))));
} }
} }
@ -148,13 +148,13 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
{ {
throw new GracefulException(Strings.ProjectDoesNotExist, filename); throw new GracefulException(LocalizableStrings.ProjectDoesNotExist, filename);
} }
var project = TryOpenProject(filename); var project = TryOpenProject(filename);
if (project == null) if (project == null)
{ {
throw new GracefulException(Strings.ProjectIsInvalid, filename); throw new GracefulException(LocalizableStrings.ProjectIsInvalid, filename);
} }
return project; return project;
@ -169,36 +169,36 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
} }
catch (ArgumentException) catch (ArgumentException)
{ {
throw new GracefulException(Strings.CouldNotFindProjectOrDirectory, directory); throw new GracefulException(LocalizableStrings.CouldNotFindProjectOrDirectory, directory);
} }
if (!dir.Exists) if (!dir.Exists)
{ {
throw new GracefulException(Strings.CouldNotFindProjectOrDirectory, directory); throw new GracefulException(LocalizableStrings.CouldNotFindProjectOrDirectory, directory);
} }
FileInfo[] files = dir.GetFiles("*proj"); FileInfo[] files = dir.GetFiles("*proj");
if (files.Length == 0) if (files.Length == 0)
{ {
throw new GracefulException(Strings.CouldNotFindAnyProjectInDirectory, directory); throw new GracefulException(LocalizableStrings.CouldNotFindAnyProjectInDirectory, directory);
} }
if (files.Length > 1) if (files.Length > 1)
{ {
throw new GracefulException(Strings.MoreThanOneProjectInDirectory, directory); throw new GracefulException(LocalizableStrings.MoreThanOneProjectInDirectory, directory);
} }
FileInfo projectFile = files.First(); FileInfo projectFile = files.First();
if (!projectFile.Exists) if (!projectFile.Exists)
{ {
throw new GracefulException(Strings.CouldNotFindAnyProjectInDirectory, directory); throw new GracefulException(LocalizableStrings.CouldNotFindAnyProjectInDirectory, directory);
} }
var ret = TryOpenProject(projectFile.FullName); var ret = TryOpenProject(projectFile.FullName);
if (ret == null) if (ret == null)
{ {
throw new GracefulException(Strings.FoundInvalidProject, projectFile.FullName); throw new GracefulException(LocalizableStrings.FoundInvalidProject, projectFile.FullName);
} }
return ret; return ret;
@ -219,14 +219,14 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
{ {
if (root.HasExistingItemWithCondition(framework, @ref)) if (root.HasExistingItemWithCondition(framework, @ref))
{ {
Reporter.Output.WriteLine(string.Format(Strings.ProjectAlreadyHasAreference, @ref)); Reporter.Output.WriteLine(string.Format(LocalizableStrings.ProjectAlreadyHasAreference, @ref));
continue; continue;
} }
numberOfAddedReferences++; numberOfAddedReferences++;
itemGroup.AppendChild(root.CreateItemElement(ProjectItemElementType, @ref)); itemGroup.AppendChild(root.CreateItemElement(ProjectItemElementType, @ref));
Reporter.Output.WriteLine(string.Format(Strings.ReferenceAddedToTheProject, @ref)); Reporter.Output.WriteLine(string.Format(LocalizableStrings.ReferenceAddedToTheProject, @ref));
} }
return numberOfAddedReferences; return numberOfAddedReferences;

View file

@ -58,7 +58,7 @@ Commands:
} }
else if (args.Length == 1) else if (args.Length == 1)
{ {
Reporter.Error.WriteLine(string.Format(Strings.RequiredArgumentNotPassed, "<command>").Red()); Reporter.Error.WriteLine(string.Format(LocalizableStrings.RequiredArgumentNotPassed, "<command>").Red());
Reporter.Output.WriteLine(HelpText); Reporter.Output.WriteLine(HelpText);
return 1; return 1;
} }
@ -76,7 +76,7 @@ Commands:
return builtin(args); return builtin(args);
} }
Reporter.Error.WriteLine(string.Format(Strings.RequiredArgumentIsInvalid, "<command>").Red()); Reporter.Error.WriteLine(string.Format(LocalizableStrings.RequiredArgumentIsInvalid, "<command>").Red());
Reporter.Output.WriteLine(HelpText); Reporter.Output.WriteLine(HelpText);
return 1; return 1;
} }

View file

@ -12,7 +12,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
public AddP2PCommand() public AddP2PCommand()
: base("dotnet") : base("dotnet")
{ {
} }
public override CommandResult Execute(string args = "") public override CommandResult Execute(string args = "")

View file

@ -8,9 +8,11 @@ using System.Collections.Generic;
namespace Microsoft.DotNet.Cli.Add.P2P.Tests namespace Microsoft.DotNet.Cli.Add.P2P.Tests
{ {
internal static class Extensions internal static class ProjectRootElementExtensions
{ {
public static int NumberOfItemGroupsWithConditionContaining(this ProjectRootElement root, string patternInCondition) public static int NumberOfItemGroupsWithConditionContaining(
this ProjectRootElement root,
string patternInCondition)
{ {
return root.ItemGroups.Count((itemGroup) => itemGroup.Condition.Contains(patternInCondition)); return root.ItemGroups.Count((itemGroup) => itemGroup.Condition.Contains(patternInCondition));
} }
@ -20,7 +22,11 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
return root.ItemGroups.Count((ig) => string.IsNullOrEmpty(ig.Condition)); return root.ItemGroups.Count((ig) => string.IsNullOrEmpty(ig.Condition));
} }
public static IEnumerable<ProjectElement> ItemsWithIncludeAndConditionContaining(this ProjectRootElement root, string itemType, string includePattern, string patternInCondition) public static IEnumerable<ProjectElement> ItemsWithIncludeAndConditionContaining(
this ProjectRootElement root,
string itemType,
string includePattern,
string patternInCondition)
{ {
return root.Items.Where((it) => return root.Items.Where((it) =>
{ {
@ -34,17 +40,29 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
}); });
} }
public static int NumberOfProjectReferencesWithIncludeAndConditionContaining(this ProjectRootElement root, string includePattern, string patternInCondition) public static int NumberOfProjectReferencesWithIncludeAndConditionContaining(
this ProjectRootElement root,
string includePattern,
string patternInCondition)
{ {
return root.ItemsWithIncludeAndConditionContaining("ProjectReference", includePattern, patternInCondition).Count(); return root.ItemsWithIncludeAndConditionContaining(
"ProjectReference",
includePattern,
patternInCondition)
.Count();
} }
public static IEnumerable<ProjectElement> ItemsWithIncludeContaining(this ProjectRootElement root, string itemType, string includePattern) public static IEnumerable<ProjectElement> ItemsWithIncludeContaining(
this ProjectRootElement root,
string itemType,
string includePattern)
{ {
return root.Items.Where((it) => it.ItemType == itemType && it.Include.Contains(includePattern)); return root.Items.Where((it) => it.ItemType == itemType && it.Include.Contains(includePattern));
} }
public static int NumberOfProjectReferencesWithIncludeContaining(this ProjectRootElement root, string includePattern) public static int NumberOfProjectReferencesWithIncludeContaining(
this ProjectRootElement root,
string includePattern)
{ {
return root.ItemsWithIncludeContaining("ProjectReference", includePattern).Count(); return root.ItemsWithIncludeContaining("ProjectReference", includePattern).Count();
} }