internal static void ShowHintForOtherTemplates(TemplateGroup templateGroup, CliTemplateInfo preferredtemplate, InstantiateCommandArgs args, TextWriter writer) { //other languages if (templateGroup.Languages.Count <= 1) { return; } string?preferredLanguage = preferredtemplate.GetLanguage(); List <string> supportedLanguages = new List <string>(); foreach (string?language in templateGroup.Languages) { if (string.IsNullOrWhiteSpace(language)) { continue; } if (!language.Equals(preferredLanguage, StringComparison.OrdinalIgnoreCase)) { supportedLanguages.Add(language); } } if (!supportedLanguages.Any()) { return; } supportedLanguages.Sort(StringComparer.OrdinalIgnoreCase); writer.WriteLine(HelpStrings.Hint_HelpForOtherLanguages, string.Join(", ", supportedLanguages)); writer.WriteLine( Example .For <NewCommand>(args.ParseResult) .WithArgument(NewCommand.ShortNameArgument, templateGroup.ShortNames[0]) .WithHelpOption() .WithOption(SharedOptionsFactory.CreateLanguageOption(), supportedLanguages.First()) .ToString().Indent()); writer.WriteLine(); //other types if (templateGroup.Types.Count <= 1) { return; } string?preferredType = preferredtemplate.GetTemplateType(); List <string> supportedTypes = new List <string>(); foreach (string?type in templateGroup.Types) { if (string.IsNullOrWhiteSpace(type)) { continue; } if (!type.Equals(preferredType, StringComparison.OrdinalIgnoreCase)) { supportedTypes.Add(type); } } if (!supportedTypes.Any()) { return; } supportedTypes.Sort(StringComparer.OrdinalIgnoreCase); writer.WriteLine(HelpStrings.Hint_HelpForOtherTypes, string.Join(", ", supportedTypes)); writer.WriteLine(Example .For <NewCommand>(args.ParseResult) .WithArgument(NewCommand.ShortNameArgument, templateGroup.ShortNames[0]) .WithHelpOption() .WithOption(SharedOptionsFactory.CreateTypeOption(), supportedTypes.First()) .ToString().Indent()); writer.WriteLine(); }
/// <summary> /// Create command for instantiation of specific template. /// </summary> /// <exception cref="InvalidTemplateParametersException">when <paramref name="template"/> has invalid template parameters.</exception> public TemplateCommand( BaseCommand instantiateCommand, IEngineEnvironmentSettings environmentSettings, TemplatePackageManager templatePackageManager, TemplateGroup templateGroup, CliTemplateInfo template, bool buildDefaultLanguageValidation = false) : base( templateGroup.ShortNames[0], template.Name + Environment.NewLine + template.Description) { _instantiateCommand = instantiateCommand; _environmentSettings = environmentSettings; _templatePackageManager = templatePackageManager; _templateGroup = templateGroup; _template = template; foreach (var item in templateGroup.ShortNames.Skip(1)) { AddAlias(item); } this.AddOption(OutputOption); this.AddOption(NameOption); this.AddOption(DryRunOption); this.AddOption(ForceOption); this.AddOption(NoUpdateCheckOption); string?templateLanguage = template.GetLanguage(); string?defaultLanguage = environmentSettings.GetDefaultLanguage(); if (!string.IsNullOrWhiteSpace(templateLanguage)) { LanguageOption = SharedOptionsFactory.CreateLanguageOption(); LanguageOption.Description = SymbolStrings.TemplateCommand_Option_Language; LanguageOption.FromAmongCaseInsensitive(new[] { templateLanguage }); if (!string.IsNullOrWhiteSpace(defaultLanguage) && buildDefaultLanguageValidation) { LanguageOption.SetDefaultValue(defaultLanguage); LanguageOption.AddValidator(optionResult => { var value = optionResult.GetValueOrDefault <string>(); if (value != template.GetLanguage()) { optionResult.ErrorMessage = "Languages don't match"; } } ); } this.AddOption(LanguageOption); } string?templateType = template.GetTemplateType(); if (!string.IsNullOrWhiteSpace(templateType)) { TypeOption = SharedOptionsFactory.CreateTypeOption(); TypeOption.Description = SymbolStrings.TemplateCommand_Option_Type; TypeOption.FromAmongCaseInsensitive(new[] { templateType }); this.AddOption(TypeOption); } if (template.BaselineInfo.Any(b => !string.IsNullOrWhiteSpace(b.Key))) { BaselineOption = SharedOptionsFactory.CreateBaselineOption(); BaselineOption.Description = SymbolStrings.TemplateCommand_Option_Baseline; BaselineOption.FromAmongCaseInsensitive(template.BaselineInfo.Select(b => b.Key).Where(b => !string.IsNullOrWhiteSpace(b)).ToArray()); this.AddOption(BaselineOption); } if (HasRunScriptPostActionDefined(template)) { AllowScriptsOption = new Option <AllowRunScripts>("--allow-scripts") { Description = SymbolStrings.TemplateCommand_Option_AllowScripts, Arity = new ArgumentArity(1, 1) }; AllowScriptsOption.SetDefaultValue(AllowRunScripts.Prompt); this.AddOption(AllowScriptsOption); } AddTemplateOptionsToCommand(template); }