Skip to content

Commit

Permalink
Merge pull request dotnet#1577 from dotnet/stabilize
Browse files Browse the repository at this point in the history
Merge stabilize into master
  • Loading branch information
mlorbetske authored Jul 7, 2018
2 parents 9b6a5ef + 04fe814 commit f34b2cc
Show file tree
Hide file tree
Showing 17 changed files with 248 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private static Option[] NewCommandVisibleArgs
Create.Option("-u|--uninstall", LocalizableStrings.UninstallHelp, Accept.ZeroOrMoreArguments()),
Create.Option("--nuget-source", LocalizableStrings.NuGetSourceHelp, Accept.OneOrMoreArguments()),
Create.Option("--type", LocalizableStrings.ShowsFilteredTemplates, Accept.ExactlyOneArgument()),
Create.Option("--dry-run", LocalizableStrings.DryRunDescription, Accept.NoArguments()),
Create.Option("--force", LocalizableStrings.ForcesTemplateCreation, Accept.NoArguments()),
Create.Option("-lang|--language", LocalizableStrings.LanguageParameter,
Accept.ExactlyOneArgument()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface INewCommandInput

IList<string> InstallNuGetSourceList { get; }

bool IsDryRun { get; }

IList<string> ToUninstallList { get; }

bool IsForceFlagSpecified { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ public IReadOnlyList<string> Tokens

public IList<string> ToUninstallList => _parseResult.GetArgumentListAtPath(new[] { _commandName, "uninstall" })?.ToList();

public bool IsDryRun => _parseResult.HasAppliedOption(new[] { _commandName, "dry-run" });

public bool IsForceFlagSpecified => _parseResult.HasAppliedOption(new[] { _commandName, "force" });

public bool IsHelpFlagSpecified => _parseResult.HasAppliedOption(new[] { _commandName, "help" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static CreationResultStatus DisplayHelpForAmbiguousTemplateGroup(Templat
}
else if (commandInput.IsListFlagSpecified || commandInput.IsHelpFlagSpecified)
{
return CreationResultStatus.Success;
return !templateResolutionResult.IsNoTemplatesMatchedState ? CreationResultStatus.Success : CreationResultStatus.NotFound;
}
else
{
Expand Down Expand Up @@ -298,56 +298,17 @@ private static void ShowContextAndTemplateNameMismatchHelp(TemplateListResolutio
return;
}

GetContextBasedAndOtherPartialMatches(templateResolutionResult, out IReadOnlyList<IReadOnlyList<ITemplateMatchInfo>> contextProblemMatchGroups, out IReadOnlyList<IReadOnlyList<ITemplateMatchInfo>> remainingPartialMatchGroups);
DisplayPartialNameMatchAndContextProblems(templateName, context, contextProblemMatchGroups, remainingPartialMatchGroups);
}

private static void GetContextBasedAndOtherPartialMatches(TemplateListResolutionResult templateResolutionResult, out IReadOnlyList<IReadOnlyList<ITemplateMatchInfo>> contextProblemMatchGroups, out IReadOnlyList<IReadOnlyList<ITemplateMatchInfo>> remainingPartialMatchGroups)
{
Dictionary<string, List<ITemplateMatchInfo>> contextProblemMatches = new Dictionary<string, List<ITemplateMatchInfo>>();
Dictionary<string, List<ITemplateMatchInfo>> remainingPartialMatches = new Dictionary<string, List<ITemplateMatchInfo>>();

// this filtering / grouping ignores language differences.
foreach (ITemplateMatchInfo template in templateResolutionResult.GetBestTemplateMatchList(true))
{
if (template.MatchDisposition.Any(x => x.Location == MatchLocation.Context && x.Kind != MatchKind.Exact))
{
if (!contextProblemMatches.TryGetValue(template.Info.GroupIdentity, out List<ITemplateMatchInfo> templateGroup))
{
templateGroup = new List<ITemplateMatchInfo>();
contextProblemMatches.Add(template.Info.GroupIdentity, templateGroup);
}

templateGroup.Add(template);
}
else if (!templateResolutionResult.UsingContextMatches
&& template.MatchDisposition.Any(t => t.Location != MatchLocation.Context && t.Kind != MatchKind.Mismatch && t.Kind != MatchKind.Unspecified))
{
if (!remainingPartialMatches.TryGetValue(template.Info.GroupIdentity, out List<ITemplateMatchInfo> templateGroup))
{
templateGroup = new List<ITemplateMatchInfo>();
remainingPartialMatches.Add(template.Info.GroupIdentity, templateGroup);
}

templateGroup.Add(template);
}
}

// context mismatches from the "matched" templates
contextProblemMatchGroups = contextProblemMatches.Values.ToList();

// other templates with anything matching
remainingPartialMatchGroups = remainingPartialMatches.Values.ToList();
DisplayPartialNameMatchAndContextProblems(templateName, context, templateResolutionResult);
}

private static void DisplayPartialNameMatchAndContextProblems(string templateName, string context, IReadOnlyList<IReadOnlyList<ITemplateMatchInfo>> contextProblemMatchGroups, IReadOnlyList<IReadOnlyList<ITemplateMatchInfo>> remainingPartialMatchGroups)
private static void DisplayPartialNameMatchAndContextProblems(string templateName, string context, TemplateListResolutionResult templateResolutionResult)
{
if (contextProblemMatchGroups.Count + remainingPartialMatchGroups.Count > 1)
if (templateResolutionResult.IsTemplateAmbiguous)
{
// Unable to determine the desired template from the input template name: {0}..
Reporter.Error.WriteLine(string.Format(LocalizableStrings.AmbiguousInputTemplateName, templateName).Bold().Red());
}
else if (contextProblemMatchGroups.Count + remainingPartialMatchGroups.Count == 0)
else if (templateResolutionResult.IsNoTemplatesMatchedState)
{
// No templates matched the input template name: {0}
Reporter.Error.WriteLine(string.Format(LocalizableStrings.NoTemplatesMatchName, templateName).Bold().Red());
Expand All @@ -357,7 +318,7 @@ private static void DisplayPartialNameMatchAndContextProblems(string templateNam

bool anythingReported = false;

foreach (IReadOnlyList<ITemplateMatchInfo> templateGroup in contextProblemMatchGroups)
foreach (IReadOnlyList<ITemplateMatchInfo> templateGroup in templateResolutionResult.ContextProblemMatchGroups)
{
// all templates in a group should have the same context & name
if (templateGroup[0].Info.Tags != null && templateGroup[0].Info.Tags.TryGetValue("type", out ICacheTag typeTag))
Expand All @@ -380,7 +341,7 @@ private static void DisplayPartialNameMatchAndContextProblems(string templateNam
}
}

if (remainingPartialMatchGroups.Count > 0)
if (templateResolutionResult.RemainingPartialMatchGroups.Count > 0)
{
// The following templates partially match the input. Be more specific with the template name and/or language
Reporter.Error.WriteLine(LocalizableStrings.TemplateMultiplePartialNameMatches.Bold().Red());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ public static void ShowTemplateGroupHelp(IReadOnlyList<ITemplateMatchInfo> templ
IReadOnlyList<ITemplateInfo> templateInfoList = templateGroup.Select(x => x.Info).ToList();
ShowTemplateDetailHeaders(templateInfoList);

TemplateGroupParameterDetails groupParameterDetails = DetermineParameterDispositionsForTemplateGroup(templateInfoList, environmentSettings, commandInput, hostDataLoader, templateCreator);
TemplateGroupParameterDetails? groupParameterDetails = DetermineParameterDispositionsForTemplateGroup(templateInfoList, environmentSettings, commandInput, hostDataLoader, templateCreator);

// get the input params valid for any param in the group
IReadOnlyDictionary<string, string> inputTemplateParams = CoalesceInputParameterValuesFromTemplateGroup(templateGroup);
if (groupParameterDetails != null)
{
// get the input params valid for any param in the group
IReadOnlyDictionary<string, string> inputTemplateParams = CoalesceInputParameterValuesFromTemplateGroup(templateGroup);

ShowParameterHelp(inputTemplateParams, showImplicitlyHiddenParams, groupParameterDetails, environmentSettings);
ShowParameterHelp(inputTemplateParams, showImplicitlyHiddenParams, groupParameterDetails.Value, environmentSettings);
}
else
{
Reporter.Error.WriteLine(string.Format(LocalizableStrings.MissingTemplateContentDetected, commandInput.CommandName).Bold().Red());
}
}

private static void ShowTemplateDetailHeaders(IReadOnlyList<ITemplateInfo> templateGroup)
Expand Down Expand Up @@ -260,7 +267,7 @@ private static IReadOnlyDictionary<string, string> CoalesceInputParameterValuesF
return inputValues;
}

private static TemplateGroupParameterDetails DetermineParameterDispositionsForTemplateGroup(IReadOnlyList<ITemplateInfo> templateGroup, IEngineEnvironmentSettings environmentSettings, INewCommandInput commandInput, IHostSpecificDataLoader hostDataLoader, TemplateCreator templateCreator)
private static TemplateGroupParameterDetails? DetermineParameterDispositionsForTemplateGroup(IReadOnlyList<ITemplateInfo> templateGroup, IEngineEnvironmentSettings environmentSettings, INewCommandInput commandInput, IHostSpecificDataLoader hostDataLoader, TemplateCreator templateCreator)
{
HashSet<string> groupUserParamsWithInvalidValues = new HashSet<string>(StringComparer.Ordinal);
bool groupHasPostActionScriptRunner = false;
Expand All @@ -277,7 +284,14 @@ private static TemplateGroupParameterDetails DetermineParameterDispositionsForTe

foreach (ITemplateInfo templateInfo in templateGroup.OrderByDescending(x => x.Precedence))
{
TemplateUsageInformation usageInformation = TemplateUsageHelp.GetTemplateUsageInformation(templateInfo, environmentSettings, commandInput, hostDataLoader, templateCreator);
TemplateUsageInformation? usageInformationNullable = TemplateUsageHelp.GetTemplateUsageInformation(templateInfo, environmentSettings, commandInput, hostDataLoader, templateCreator);

if (usageInformationNullable == null)
{
return null;
}

TemplateUsageInformation usageInformation = usageInformationNullable.Value;
HostSpecificTemplateData hostSpecificTemplateData = hostDataLoader.ReadHostSpecificTemplateData(templateInfo);
HashSet<string> parametersToExplicitlyHide = hostSpecificTemplateData?.HiddenParameterNames ?? new HashSet<string>(StringComparer.Ordinal);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static IEnumerable<ITemplateParameter> FilterParamsForHelp(IEnumerable<IT
IList<ITemplateParameter> filteredParams = parameterDefinitions
.Where(x => x.Priority != TemplateParameterPriority.Implicit
&& !hiddenParams.Contains(x.Name)
&& string.Equals(x.Type, "parameter", StringComparison.OrdinalIgnoreCase)
&& !string.Equals(x.Name, "type", StringComparison.OrdinalIgnoreCase)
&& !string.Equals(x.Name, "language", StringComparison.OrdinalIgnoreCase)
&& (showImplicitlyHiddenParams || x.DataType != "choice" || x.Choices.Count > 1 || (parametersToAlwaysShow?.Contains(x.Name) ?? false))).ToList(); // for filtering "tags"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,20 @@ private static bool GenerateUsageForTemplate(ITemplateInfo templateInfo, IHostSp

// TODO: rework this method... it's a bit of a god-method, for very specific purposes.
// Number of times I've deferred on reworking this method: 4
internal static TemplateUsageInformation GetTemplateUsageInformation(ITemplateInfo templateInfo, IEngineEnvironmentSettings environmentSettings, INewCommandInput commandInput, IHostSpecificDataLoader hostDataLoader, TemplateCreator templateCreator)
internal static TemplateUsageInformation? GetTemplateUsageInformation(ITemplateInfo templateInfo, IEngineEnvironmentSettings environmentSettings, INewCommandInput commandInput, IHostSpecificDataLoader hostDataLoader, TemplateCreator templateCreator)
{
IParameterSet allParams;
IReadOnlyList<string> userParamsWithInvalidValues;
HashSet<string> userParamsWithDefaultValues;
bool hasPostActionScriptRunner;

ITemplate template = environmentSettings.SettingsLoader.LoadTemplate(templateInfo, commandInput.BaselineName);

if (template == null)
{
return null;
}

TemplateListResolver.ParseTemplateArgs(templateInfo, hostDataLoader, commandInput);
allParams = templateCreator.SetupDefaultParamValuesFromTemplateAndHost(template, template.DefaultName ?? "testName", out IReadOnlyList<string> defaultParamsWithInvalidValues);
templateCreator.ResolveUserParameters(template, allParams, commandInput.InputTemplateParams, out userParamsWithInvalidValues);
Expand Down
42 changes: 39 additions & 3 deletions src/Microsoft.TemplateEngine.Cli/LocalizableStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions src/Microsoft.TemplateEngine.Cli/LocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,10 @@ Run 'dotnet {1} --show-aliases' with no args to show all aliases.</value>
<value>Some partially matched templates may not support these input switches:</value>
</data>
<data name="CommitHash" xml:space="preserve">
<value> Commit Hash: {0}</value>
<value>Commit Hash:</value>
</data>
<data name="Version" xml:space="preserve">
<value> Version: {0}</value>
<value>Version:</value>
</data>
<data name="InstalledItems" xml:space="preserve">
<value>Currently installed items:</value>
Expand Down Expand Up @@ -607,4 +607,16 @@ Run 'dotnet {1} --show-aliases' with no args to show all aliases.</value>
<data name="SwitchWithoutValueDefaultFootnote" xml:space="preserve">
<value>* Indicates the value used if the switch is provided without a value.</value>
</data>
</root>
<data name="DryRunDescription" xml:space="preserve">
<value>Displays a summary of what would happen if the given command line were run if it would result in a template creation.</value>
</data>
<data name="ActionWouldHaveBeenTakenAutomatically" xml:space="preserve">
<value>Action would have been taken automatically:</value>
</data>
<data name="FileActionsWouldHaveBeenTaken" xml:space="preserve">
<value>File actions would have been taken:</value>
</data>
<data name="MissingTemplateContentDetected" xml:space="preserve">
<value>Unable to locate the specified template content, the template cache may be corrupted. Try running 'dotnet {0} --debug:reinit' to fix the issue.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.1-alpha-167" />
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.0" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit f34b2cc

Please sign in to comment.