Localization

This commit is contained in:
Mike Lorbetske 2016-12-16 16:26:22 -08:00
parent cfa0e5cbd4
commit ecfc0e10ba
4 changed files with 211 additions and 100 deletions

View file

@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Tools.New3
{ {
public static CommandOption Help(this CommandLineApplication app) public static CommandOption Help(this CommandLineApplication app)
{ {
return app.Option("-h|--help", "Displays help for this command.", CommandOptionType.NoValue); return app.Option("-h|--help", LocalizableStrings.DisplaysHelp, CommandOptionType.NoValue);
} }
public static IReadOnlyDictionary<string, IList<string>> ParseExtraArgs(this CommandLineApplication app, IList<string> extraArgFileNames) public static IReadOnlyDictionary<string, IList<string>> ParseExtraArgs(this CommandLineApplication app, IList<string> extraArgFileNames)
@ -36,8 +36,11 @@ namespace Microsoft.DotNet.Tools.New3
{ {
if(property.Value.Type == JTokenType.String) if(property.Value.Type == JTokenType.String)
{ {
IList<string> values = new List<string>(); IList<string> values = new List<string>
values.Add(property.Value.ToString()); {
property.Value.ToString()
};
// adding 2 dashes to the file-based params // adding 2 dashes to the file-based params
// won't work right if there's a param that should have 1 dash // won't work right if there's a param that should have 1 dash
// //
@ -75,7 +78,7 @@ namespace Microsoft.DotNet.Tools.New3
if (!key.StartsWith("-", StringComparison.Ordinal)) if (!key.StartsWith("-", StringComparison.Ordinal))
{ {
throw new Exception("Parameter names must start with -- or -"); throw new Exception(LocalizableStrings.ParameterNamePrefixError);
} }
// Check the next value. If it doesn't start with a '-' then it's a value for the current param. // Check the next value. If it doesn't start with a '-' then it's a value for the current param.
@ -95,8 +98,7 @@ namespace Microsoft.DotNet.Tools.New3
} }
} }
IList<string> valueList; if (!parameters.TryGetValue(key, out var valueList))
if (!parameters.TryGetValue(key, out valueList))
{ {
valueList = new List<string>(); valueList = new List<string>();
parameters.Add(key, valueList); parameters.Add(key, valueList);

View file

@ -90,7 +90,7 @@ namespace Microsoft.DotNet.Tools.New3
{ {
if (IsParameterNameTaken(parameter)) if (IsParameterNameTaken(parameter))
{ {
throw new Exception($"Parameter name {parameter} cannot be used for multiple purposes"); throw new Exception(string.Format(LocalizableStrings.ParameterReuseError, parameter));
} }
_defaultCommandOptions.Add(parameter); _defaultCommandOptions.Add(parameter);
@ -117,7 +117,7 @@ namespace Microsoft.DotNet.Tools.New3
{ {
if (IsParameterNameTaken(parameters[i])) if (IsParameterNameTaken(parameters[i]))
{ {
throw new Exception($"Parameter name {parameters[i]} cannot be used for multiple purposes"); throw new Exception(string.Format(LocalizableStrings.ParameterReuseError, parameters[i]));
} }
_hiddenCommandCanonicalMapping.Add(parameters[i], canonical); _hiddenCommandCanonicalMapping.Add(parameters[i], canonical);
@ -193,8 +193,7 @@ namespace Microsoft.DotNet.Tools.New3
foreach (KeyValuePair<string, IList<string>> param in allParameters) foreach (KeyValuePair<string, IList<string>> param in allParameters)
{ {
string canonicalName; if (_hiddenCommandCanonicalMapping.TryGetValue(param.Key, out string canonicalName))
if (_hiddenCommandCanonicalMapping.TryGetValue(param.Key, out canonicalName))
{ {
CommandOptionType optionType = _hiddenCommandOptions[canonicalName]; CommandOptionType optionType = _hiddenCommandOptions[canonicalName];
@ -206,14 +205,14 @@ namespace Microsoft.DotNet.Tools.New3
{ {
if (param.Value.Count != 1) if (param.Value.Count != 1)
{ {
throw new Exception($"Multiple values specified for single value parameter: {canonicalName}"); throw new Exception(string.Format(LocalizableStrings.MultipleValuesSpecifiedForSingleValuedParameter, canonicalName));
} }
} }
else // NoValue else // NoValue
{ {
if (param.Value.Count != 1 || param.Value[0] != null) if (param.Value.Count != 1 || param.Value[0] != null)
{ {
throw new Exception($"Value specified for valueless parameter: {canonicalName}"); throw new Exception(string.Format(LocalizableStrings.ValueSpecifiedForValuelessParameter, canonicalName));
} }
} }
@ -224,13 +223,13 @@ namespace Microsoft.DotNet.Tools.New3
if (_parsedTemplateParams.ContainsKey(canonicalName)) if (_parsedTemplateParams.ContainsKey(canonicalName))
{ {
// error, the same param was specified twice // error, the same param was specified twice
throw new Exception($"Parameter [{canonicalName}] was specified multiple times, including with the flag [{param.Key}]"); throw new Exception(string.Format(LocalizableStrings.ParameterSpecifiedMultipleTimes, canonicalName, param.Key));
} }
else else
{ {
if ((param.Value[0] == null) && (_templateParamDataTypeMapping[canonicalName] != "bool")) if ((param.Value[0] == null) && (_templateParamDataTypeMapping[canonicalName] != "bool"))
{ {
throw new Exception($"Parameter [{param.Key}] ({canonicalName}) must be given a value"); throw new Exception(string.Format(LocalizableStrings.ParameterMissingValue, param.Key, canonicalName));
} }
// TODO: allow for multi-valued params // TODO: allow for multi-valued params
@ -258,8 +257,7 @@ namespace Microsoft.DotNet.Tools.New3
continue; continue;
} }
string flagFullText; if (parameterNameMap == null || !parameterNameMap.TryGetValue(parameter.Name, out string flagFullText))
if (parameterNameMap == null || !parameterNameMap.TryGetValue(parameter.Name, out flagFullText))
{ {
flagFullText = parameter.Name; flagFullText = parameter.Name;
} }
@ -328,7 +326,7 @@ namespace Microsoft.DotNet.Tools.New3
if (invalidParams.Count > 0) if (invalidParams.Count > 0)
{ {
string unusableDisplayList = string.Join(", ", invalidParams); string unusableDisplayList = string.Join(", ", invalidParams);
throw new Exception($"Template is malformed. The following parameter names are invalid: {unusableDisplayList}"); throw new Exception(string.Format(LocalizableStrings.TemplateMalformedDueToBadParameters, unusableDisplayList));
} }
} }
@ -336,7 +334,7 @@ namespace Microsoft.DotNet.Tools.New3
{ {
if (_templateParamCanonicalMapping.TryGetValue(variant, out string existingCanonical)) if (_templateParamCanonicalMapping.TryGetValue(variant, out string existingCanonical))
{ {
throw new Exception($"Option variant {variant} for canonical {canonical} was already defined for canonical {existingCanonical}"); throw new Exception(string.Format(LocalizableStrings.OptionVariantAlreadyDefined, variant, canonical, existingCanonical));
} }
_templateParamCanonicalMapping[variant] = canonical; _templateParamCanonicalMapping[variant] = canonical;
@ -370,9 +368,7 @@ namespace Microsoft.DotNet.Tools.New3
{ {
string variant = variantToCanonical.Key; string variant = variantToCanonical.Key;
string canonical = variantToCanonical.Value; string canonical = variantToCanonical.Value;
if (!_canonicalToVariantsTemplateParamMap.TryGetValue(canonical, out var variantList))
IList<string> variantList;
if (!_canonicalToVariantsTemplateParamMap.TryGetValue(canonical, out variantList))
{ {
variantList = new List<string>(); variantList = new List<string>();
_canonicalToVariantsTemplateParamMap.Add(canonical, variantList); _canonicalToVariantsTemplateParamMap.Add(canonical, variantList);

View file

@ -0,0 +1,115 @@
using System;
namespace Microsoft.DotNet.Tools.New3
{
internal class LocalizableStrings
{
public const string DisplaysHelp = "Displays help for this command.";
public const string ParameterNamePrefixError = "Parameter names must start with -- or -";
public const string ParameterReuseError = "Parameter name {0} cannot be used for multiple purposes";
public const string MultipleValuesSpecifiedForSingleValuedParameter = "Multiple values specified for single value parameter: {0}";
public const string ValueSpecifiedForValuelessParameter = "Value specified for valueless parameter: {0}";
public const string ParameterSpecifiedMultipleTimes = "Parameter [{0}] was specified multiple times, including with the flag [{1}]";
public const string ParameterMissingValue = "Parameter [{0}] ({1}) must be given a value";
public const string TemplateMalformedDueToBadParameters = "Template is malformed. The following parameter names are invalid: {0}";
public const string OptionVariantAlreadyDefined = "Option variant {0} for canonical {1} was already defined for canonical {2}";
public const string ListsTemplates = "List templates containing the specified name.";
public const string NameOfOutput = "The name for the output being created. If no name is specified, the name of the current directory is used.";
public const string CreateDirectoryHelp = "Indicates whether to create a directory for the generated content.";
public const string CreateAliasHelp = "Creates an alias for the specified template.";
public const string ExtraArgsFileHelp = "Specifies a file containing additional parameters.";
public const string LocaleHelp = "The locale to use";
public const string QuietModeHelp = "Doesn't output any status information.";
public const string InstallHelp = "Installs a source or a template pack.";
public const string UpdateHelp = "Update matching templates.";
public const string CommandDescription = "Template Instantiation Commands for .NET Core CLI.";
public const string TemplateArgumentHelp = "The template to instantiate.";
public const string BadLocaleError = "Invalid format for input locale: [{0}]. Example valid formats: [en] [en-US]";
public const string AliasCreated = "Alias creation successful";
public const string AliasAlreadyExists = "Specified alias {0} already exists. Please specify a different alias.";
public const string CreateSuccessful = "The template {0} created successfully.";
public const string CreateFailed = "Template {0} could not be created. Error returned was: {1}";
public const string InstallSuccessful = "{0} was installed successfully.";
public const string InstallFailed = "{0} could not be installed. Error returned was: {1}.";
public const string MissingRequiredParameter = "Mandatory parameter {0} missing for template {1}.";
public const string GettingReady = "Getting ready...";
public const string InvalidInputSwitch = "Invalid input switch:";
public const string CheckingForUpdates = "Checking for updates for {0}...";
public const string UpdateAvailable = "An update for {0} is available...";
public const string NoUpdates = "No updates were found.";
public const string InstallingUpdates = "Installing updates...";
public const string BadPackageSpec = "Package [{0}] is not a valid package specification";
public const string Templates = "Templates";
public const string ShortName = "Short Name";
public const string Alias = "Alias";
public const string CurrentConfiguration = "Current configuration:";
public const string NoItems = "(No Items)";
public const string MountPoints = "Mount Points";
public const string MountPointFactories = "Mount Point Factories";
public const string Generators = "Generators";
public const string Id = "Id";
public const string Parent = "Parent";
public const string Assembly = "Assembly";
public const string Type = "Type";
public const string Factory = "Factory";
public const string Author = "Author: {0}";
public const string Description = "Description: {0}";
public const string Options = "Options:";
public const string ConfiguredValue = "Configured Value: {0}";
public const string DefaultValue = "Default: {0}";
public const string NoParameters = " (No Parameters)";
}
}

View file

@ -28,9 +28,9 @@ namespace Microsoft.DotNet.Tools.New3
private static void SetupInternalCommands(ExtendedCommandParser appExt) private static void SetupInternalCommands(ExtendedCommandParser appExt)
{ {
// visible // visible
appExt.InternalOption("-l|--list", "--list", "List templates containing the specified name.", CommandOptionType.NoValue); appExt.InternalOption("-l|--list", "--list", LocalizableStrings.ListsTemplates, CommandOptionType.NoValue);
appExt.InternalOption("-n|--name", "--name", "The name for the output being created. If no name is specified, the name of the current directory is used.", CommandOptionType.SingleValue); appExt.InternalOption("-n|--name", "--name", LocalizableStrings.NameOfOutput, CommandOptionType.SingleValue);
appExt.InternalOption("-h|--help", "--help", "Display help for the indicated template's parameters.", CommandOptionType.NoValue); appExt.InternalOption("-h|--help", "--help", LocalizableStrings.DisplaysHelp, CommandOptionType.NoValue);
// hidden // hidden
appExt.HiddenInternalOption("-d|--dir", "--dir", CommandOptionType.NoValue); appExt.HiddenInternalOption("-d|--dir", "--dir", CommandOptionType.NoValue);
@ -48,14 +48,14 @@ namespace Microsoft.DotNet.Tools.New3
// Preserve these for now - they've got the help text, in case we want it back. // Preserve these for now - they've got the help text, in case we want it back.
// (they'll need to get converted to extended option calls) // (they'll need to get converted to extended option calls)
// //
//CommandOption dirOption = app.Option("-d|--dir", "Indicates whether to create a directory for the generated content.", CommandOptionType.NoValue); //CommandOption dirOption = app.Option("-d|--dir", LocalizableStrings.CreateDirectoryHelp, CommandOptionType.NoValue);
//CommandOption aliasOption = app.Option("-a|--alias", "Creates an alias for the specified template.", CommandOptionType.SingleValue); //CommandOption aliasOption = app.Option("-a|--alias", LocalizableStrings.CreateAliasHelp, CommandOptionType.SingleValue);
//CommandOption parametersFilesOption = app.Option("-x|--extra-args", "Specifies a file containing additional parameters.", CommandOptionType.MultipleValue); //CommandOption parametersFilesOption = app.Option("-x|--extra-args", LocalizableString.ExtraArgsFileHelp, CommandOptionType.MultipleValue);
//CommandOption localeOption = app.Option("--locale", "The locale to use", CommandOptionType.SingleValue); //CommandOption localeOption = app.Option("--locale", LocalizableStrings.LocaleHelp, CommandOptionType.SingleValue);
//CommandOption quietOption = app.Option("--quiet", "Doesn't output any status information.", CommandOptionType.NoValue); //CommandOption quietOption = app.Option("--quiet", LocalizableStrings.QuietModeHelp, CommandOptionType.NoValue);
//CommandOption installOption = app.Option("-i|--install", "Installs a source or a template pack.", CommandOptionType.MultipleValue); //CommandOption installOption = app.Option("-i|--install", LocalizableStrings.InstallHelp, CommandOptionType.MultipleValue);
//CommandOption update = app.Option("--update", "Update matching templates.", CommandOptionType.NoValue); //CommandOption update = app.Option("--update", LocalizableStrings.UpdateHelp, CommandOptionType.NoValue);
} }
public static int Run(string[] args) public static int Run(string[] args)
@ -66,11 +66,11 @@ namespace Microsoft.DotNet.Tools.New3
ExtendedCommandParser app = new ExtendedCommandParser() ExtendedCommandParser app = new ExtendedCommandParser()
{ {
Name = "dotnet new3", Name = "dotnet new",
FullName = "Template Instantiation Commands for .NET Core CLI." FullName = LocalizableStrings.CommandDescription
}; };
SetupInternalCommands(app); SetupInternalCommands(app);
CommandArgument templateNames = app.Argument("template", "The template to instantiate."); CommandArgument templateNames = app.Argument("template", LocalizableStrings.TemplateArgumentHelp);
app.OnExecute(async () => app.OnExecute(async () =>
{ {
@ -90,7 +90,7 @@ namespace Microsoft.DotNet.Tools.New3
string newLocale = app.InternalParamValue("--locale"); string newLocale = app.InternalParamValue("--locale");
if (!ValidateLocaleFormat(newLocale)) if (!ValidateLocaleFormat(newLocale))
{ {
EngineEnvironmentSettings.Host.LogMessage(string.Format("Invalid format for input locale: [{0}]. Example valid formats: [en] [en-US]", newLocale)); EngineEnvironmentSettings.Host.LogMessage(string.Format(LocalizableStrings.BadLocaleError, newLocale));
return -1; return -1;
} }
@ -115,7 +115,7 @@ namespace Microsoft.DotNet.Tools.New3
return resultCode; return resultCode;
} }
return await CreateTemplate(app, templateNames.Value); return await CreateTemplateAsync(app, templateNames.Value);
}); });
int result; int result;
@ -159,7 +159,7 @@ namespace Microsoft.DotNet.Tools.New3
return result; return result;
} }
private static async Task<int> CreateTemplate(ExtendedCommandParser app, string templateName) private static async Task<int> CreateTemplateAsync(ExtendedCommandParser app, string templateName)
{ {
string nameValue = app.InternalParamValue("--name"); string nameValue = app.InternalParamValue("--name");
string fallbackName = new DirectoryInfo(Directory.GetCurrentDirectory()).Name; string fallbackName = new DirectoryInfo(Directory.GetCurrentDirectory()).Name;
@ -176,32 +176,29 @@ namespace Microsoft.DotNet.Tools.New3
{ {
case CreationResultStatus.AliasSucceeded: case CreationResultStatus.AliasSucceeded:
// TODO: get this localized - in the mean time just list the templates, showing the alias // TODO: get this localized - in the mean time just list the templates, showing the alias
//EngineEnvironmentSettings.Host.LogMessage("Alias creation successful"); //EngineEnvironmentSettings.Host.LogMessage(LocalizableStrings.AliasCreated);
ListTemplates(templateName); ListTemplates(templateName);
break; break;
case CreationResultStatus.AliasFailed: case CreationResultStatus.AliasFailed:
EngineEnvironmentSettings.Host.LogMessage(string.Format("Specified alias {0} already exists. Please specify a different alias.", aliasName)); EngineEnvironmentSettings.Host.LogMessage(string.Format(LocalizableStrings.AliasAlreadyExists, aliasName));
ListTemplates(templateName); ListTemplates(templateName);
break; break;
case CreationResultStatus.CreateSucceeded: case CreationResultStatus.CreateSucceeded:
EngineEnvironmentSettings.Host.LogMessage(string.Format("The template {0} created successfully. Please run \"dotnet restore\" to get started!", resultTemplateName)); EngineEnvironmentSettings.Host.LogMessage(string.Format(LocalizableStrings.CreateSuccessful, resultTemplateName));
break; break;
case CreationResultStatus.CreateFailed: case CreationResultStatus.CreateFailed:
EngineEnvironmentSettings.Host.LogMessage(string.Format("Template {0} could not be created. Error returned was: {1}", resultTemplateName, instantiateResult.Message)); case CreationResultStatus.TemplateNotFound:
EngineEnvironmentSettings.Host.LogMessage(string.Format(LocalizableStrings.CreateFailed, resultTemplateName, instantiateResult.Message));
ListTemplates(templateName); ListTemplates(templateName);
break; break;
case CreationResultStatus.InstallSucceeded: case CreationResultStatus.InstallSucceeded:
EngineEnvironmentSettings.Host.LogMessage(string.Format("The template {0} installed successfully. You can use \"dotnet new {0}\" to get started with the new template.", resultTemplateName)); EngineEnvironmentSettings.Host.LogMessage(string.Format(LocalizableStrings.InstallSuccessful, resultTemplateName));
break; break;
case CreationResultStatus.InstallFailed: case CreationResultStatus.InstallFailed:
EngineEnvironmentSettings.Host.LogMessage(string.Format("Template {0} could not be created. Error returned was: {1}.", resultTemplateName, instantiateResult.Message)); EngineEnvironmentSettings.Host.LogMessage(string.Format(LocalizableStrings.InstallFailed, resultTemplateName, instantiateResult.Message));
break; break;
case CreationResultStatus.MissingMandatoryParam: case CreationResultStatus.MissingMandatoryParam:
EngineEnvironmentSettings.Host.LogMessage(string.Format("Mandatory parameter {0} missing for template {1}.", instantiateResult.Message, resultTemplateName)); EngineEnvironmentSettings.Host.LogMessage(string.Format(LocalizableStrings.MissingRequiredParameter, instantiateResult.Message, resultTemplateName));
break;
case CreationResultStatus.TemplateNotFound:
EngineEnvironmentSettings.Host.LogMessage(string.Format("Template {0} could not be created. Error returned was: {1}.", resultTemplateName, instantiateResult.Message));
ListTemplates(templateName);
break; break;
default: default:
break; break;
@ -233,7 +230,7 @@ namespace Microsoft.DotNet.Tools.New3
{ {
if (!app.InternalParamHasValue("--quiet")) if (!app.InternalParamHasValue("--quiet"))
{ {
Reporter.Output.WriteLine("Getting things ready for first use..."); Reporter.Output.WriteLine(LocalizableStrings.GettingReady);
} }
ConfigureEnvironment(); ConfigureEnvironment();
@ -279,7 +276,7 @@ namespace Microsoft.DotNet.Tools.New3
if (app.RemainingParameters.Any(x => !x.Key.StartsWith("--debug:"))) if (app.RemainingParameters.Any(x => !x.Key.StartsWith("--debug:")))
{ {
EngineEnvironmentSettings.Host.LogMessage("Invalid input switch:"); EngineEnvironmentSettings.Host.LogMessage(LocalizableStrings.InvalidInputSwitch);
foreach (string flag in app.RemainingParameters.Keys) foreach (string flag in app.RemainingParameters.Keys)
{ {
EngineEnvironmentSettings.Host.LogMessage($"\t{flag}"); EngineEnvironmentSettings.Host.LogMessage($"\t{flag}");
@ -357,7 +354,7 @@ namespace Microsoft.DotNet.Tools.New3
// { // {
// if (!quiet) // if (!quiet)
// { // {
// Reporter.Output.WriteLine($"Checking for updates for {src.Alias}..."); // Reporter.Output.WriteLine(string.Format(LocalizableStrings.CheckingForUpdates, src.Alias));
// } // }
// bool updatesReady; // bool updatesReady;
@ -375,7 +372,7 @@ namespace Microsoft.DotNet.Tools.New3
// { // {
// if (!quiet) // if (!quiet)
// { // {
// Reporter.Output.WriteLine($"An update for {src.Alias} is available..."); // Reporter.Output.WriteLine(string.Format(LocalizableStrings.UpdateAvailable, src.Alias));
// } // }
// string packageId = src.ParentSource != null // string packageId = src.ParentSource != null
@ -390,7 +387,7 @@ namespace Microsoft.DotNet.Tools.New3
// { // {
// if (!quiet) // if (!quiet)
// { // {
// Reporter.Output.WriteLine("No updates were found."); // Reporter.Output.WriteLine(LocalizableStrings.NoUpdates);
// } // }
// return 0; // return 0;
@ -398,7 +395,7 @@ namespace Microsoft.DotNet.Tools.New3
// if (!quiet) // if (!quiet)
// { // {
// Reporter.Output.WriteLine("Installing updates..."); // Reporter.Output.WriteLine(LocalizableString.InstallingUpdates);
// } // }
// List<string> installCommands = new List<string>(); // List<string> installCommands = new List<string>();
@ -416,8 +413,8 @@ namespace Microsoft.DotNet.Tools.New3
// installCommands.Add("--quiet"); // installCommands.Add("--quiet");
// uninstallCommands.Add("--quiet"); // uninstallCommands.Add("--quiet");
// Command.CreateDotNet("new3", uninstallCommands).ForwardStdOut().ForwardStdErr().Execute(); // Command.CreateDotNet("new", uninstallCommands).ForwardStdOut().ForwardStdErr().Execute();
// Command.CreateDotNet("new3", installCommands).ForwardStdOut().ForwardStdErr().Execute(); // Command.CreateDotNet("new", installCommands).ForwardStdOut().ForwardStdErr().Execute();
// Broker.ComponentRegistry.ForceReinitialize(); // Broker.ComponentRegistry.ForceReinitialize();
// if (!quiet) // if (!quiet)
@ -430,24 +427,24 @@ namespace Microsoft.DotNet.Tools.New3
private static void ConfigureEnvironment() private static void ConfigureEnvironment()
{ {
string userNuGetConfig = $@"<?xml version=""1.0"" encoding=""utf-8""?> string[] packageList;
<configuration>
<packageSources>
<add key=""dotnet new3 builtins"" value = ""{Paths.Global.BuiltInsFeed}""/>
</packageSources>
</configuration>";
Paths.User.NuGetConfig.WriteAllText(userNuGetConfig);
string[] packageList = Paths.Global.DefaultInstallPackageList.ReadAllText().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); if (Paths.Global.DefaultInstallPackageList.FileExists())
if (packageList.Length > 0)
{ {
InstallPackages(packageList, true); packageList = Paths.Global.DefaultInstallPackageList.ReadAllText().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
if (packageList.Length > 0)
{
InstallPackages(packageList, true);
}
} }
packageList = Paths.Global.DefaultInstallTemplateList.ReadAllText().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); if (Paths.Global.DefaultInstallTemplateList.FileExists())
if (packageList.Length > 0)
{ {
InstallPackages(packageList, true); packageList = Paths.Global.DefaultInstallTemplateList.ReadAllText().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
if (packageList.Length > 0)
{
InstallPackages(packageList, true);
}
} }
} }
@ -478,7 +475,7 @@ namespace Microsoft.DotNet.Tools.New3
} }
catch catch
{ {
EngineEnvironmentSettings.Host.OnNonCriticalError("InvalidPackageSpecification", string.Format($"Package [{pkg}] is not a valid package specification"), null, 0); EngineEnvironmentSettings.Host.OnNonCriticalError("InvalidPackageSpecification", string.Format(LocalizableStrings.BadPackageSpec, pkg), null, 0);
} }
} }
@ -494,36 +491,36 @@ namespace Microsoft.DotNet.Tools.New3
{ {
IEnumerable<ITemplateInfo> results = TemplateCreator.List(templateNames); IEnumerable<ITemplateInfo> results = TemplateCreator.List(templateNames);
HelpFormatter<ITemplateInfo> formatter = new HelpFormatter<ITemplateInfo>(results, 6, '-', false); HelpFormatter<ITemplateInfo> formatter = new HelpFormatter<ITemplateInfo>(results, 6, '-', false);
formatter.DefineColumn(delegate (ITemplateInfo t) { return t.Name; }, "Templates"); formatter.DefineColumn(delegate (ITemplateInfo t) { return t.Name; }, LocalizableStrings.Templates);
formatter.DefineColumn(delegate (ITemplateInfo t) { return $"[{t.ShortName}]"; }, "Short Name"); formatter.DefineColumn(delegate (ITemplateInfo t) { return $"[{t.ShortName}]"; }, LocalizableStrings.ShortName);
formatter.DefineColumn(delegate (ITemplateInfo t) { return AliasRegistry.GetAliasForTemplate(t) ?? ""; }, "Alias"); formatter.DefineColumn(delegate (ITemplateInfo t) { return AliasRegistry.GetAliasForTemplate(t) ?? ""; }, LocalizableStrings.Alias);
Reporter.Output.WriteLine(formatter.Layout()); Reporter.Output.WriteLine(formatter.Layout());
} }
private static void ShowConfig() private static void ShowConfig()
{ {
Reporter.Output.WriteLine("dotnet new3 current configuration:"); Reporter.Output.WriteLine(LocalizableStrings.CurrentConfiguration);
Reporter.Output.WriteLine(" "); Reporter.Output.WriteLine(" ");
TableFormatter.Print(SettingsLoader.MountPoints, "(No Items)", " ", '-', new Dictionary<string, Func<MountPointInfo, object>> TableFormatter.Print(SettingsLoader.MountPoints, LocalizableStrings.NoItems, " ", '-', new Dictionary<string, Func<MountPointInfo, object>>
{ {
{"Mount Points", x => x.Place}, {LocalizableStrings.MountPoints, x => x.Place},
{"Id", x => x.MountPointId}, {LocalizableStrings.Id, x => x.MountPointId},
{"Parent", x => x.ParentMountPointId}, {LocalizableStrings.Parent, x => x.ParentMountPointId},
{"Factory", x => x.MountPointFactoryId} {LocalizableStrings.Factory, x => x.MountPointFactoryId}
}); });
TableFormatter.Print(SettingsLoader.Components.OfType<IMountPointFactory>(), "(No Items)", " ", '-', new Dictionary<string, Func<IMountPointFactory, object>> TableFormatter.Print(SettingsLoader.Components.OfType<IMountPointFactory>(), LocalizableStrings.NoItems, " ", '-', new Dictionary<string, Func<IMountPointFactory, object>>
{ {
{"Mount Point Factories", x => x.Id}, {LocalizableStrings.MountPointFactories, x => x.Id},
{"Type", x => x.GetType().FullName}, {LocalizableStrings.Type, x => x.GetType().FullName},
{"Assembly", x => x.GetType().GetTypeInfo().Assembly.FullName} {LocalizableStrings.Assembly, x => x.GetType().GetTypeInfo().Assembly.FullName}
}); });
TableFormatter.Print(SettingsLoader.Components.OfType<IGenerator>(), "(No Items)", " ", '-', new Dictionary<string, Func<IGenerator, object>> TableFormatter.Print(SettingsLoader.Components.OfType<IGenerator>(), LocalizableStrings.NoItems, " ", '-', new Dictionary<string, Func<IGenerator, object>>
{ {
{"Generators", x => x.Id}, {LocalizableStrings.Generators, x => x.Id},
{"Type", x => x.GetType().FullName}, {LocalizableStrings.Type, x => x.GetType().FullName},
{"Assembly", x => x.GetType().GetTypeInfo().Assembly.FullName} {LocalizableStrings.Assembly, x => x.GetType().GetTypeInfo().Assembly.FullName}
}); });
} }
@ -560,12 +557,12 @@ namespace Microsoft.DotNet.Tools.New3
Reporter.Output.WriteLine(templateInfo.Name); Reporter.Output.WriteLine(templateInfo.Name);
if (!string.IsNullOrWhiteSpace(templateInfo.Author)) if (!string.IsNullOrWhiteSpace(templateInfo.Author))
{ {
Reporter.Output.WriteLine($"Author: {templateInfo.Author}"); Reporter.Output.WriteLine(string.Format(LocalizableStrings.Author, templateInfo.Author));
} }
if (!string.IsNullOrWhiteSpace(templateInfo.Description)) if (!string.IsNullOrWhiteSpace(templateInfo.Description))
{ {
Reporter.Output.WriteLine($"Description: {templateInfo.Description}"); Reporter.Output.WriteLine(string.Format(LocalizableStrings.Description, templateInfo.Description));
} }
ITemplate template = SettingsLoader.LoadTemplate(templateInfo); ITemplate template = SettingsLoader.LoadTemplate(templateInfo);
@ -584,14 +581,15 @@ namespace Microsoft.DotNet.Tools.New3
{ {
HelpFormatter<ITemplateParameter> formatter = new HelpFormatter<ITemplateParameter>(filteredParams, 2, null, true); HelpFormatter<ITemplateParameter> formatter = new HelpFormatter<ITemplateParameter>(filteredParams, 2, null, true);
formatter.DefineColumn(delegate (ITemplateParameter param) formatter.DefineColumn(
{ param =>
// the key is guaranteed to exist {
IList<string> variants = app.CanonicalToVariantsTemplateParamMap[param.Name]; // the key is guaranteed to exist
string options = string.Join("|", variants.Reverse()); IList<string> variants = app.CanonicalToVariantsTemplateParamMap[param.Name];
return " " + options; string options = string.Join("|", variants.Reverse());
}, return " " + options;
"Options:" },
LocalizableStrings.Options
); );
formatter.DefineColumn(delegate (ITemplateParameter param) formatter.DefineColumn(delegate (ITemplateParameter param)
@ -617,13 +615,13 @@ namespace Microsoft.DotNet.Tools.New3
&& !string.IsNullOrEmpty(param.DefaultValue) && !string.IsNullOrEmpty(param.DefaultValue)
&& !string.Equals(param.DefaultValue, resolvedValue)) && !string.Equals(param.DefaultValue, resolvedValue))
{ {
displayValue.AppendLine("Configured Value: " + resolvedValue); displayValue.AppendLine(string.Format(LocalizableStrings.ConfiguredValue, resolvedValue));
} }
} }
if (!string.IsNullOrEmpty(param.DefaultValue)) if (!string.IsNullOrEmpty(param.DefaultValue))
{ {
displayValue.AppendLine("Default: " + param.DefaultValue); displayValue.AppendLine(string.Format(LocalizableStrings.DefaultValue, param.DefaultValue));
} }
return displayValue.ToString(); return displayValue.ToString();
@ -635,7 +633,7 @@ namespace Microsoft.DotNet.Tools.New3
} }
else else
{ {
Reporter.Output.WriteLine(" (No Parameters)"); Reporter.Output.WriteLine(LocalizableStrings.NoParameters);
} }
} }
} }