Exemplo n.º 1
0
        private static void ShowConfig()
        {
            Reporter.Output.WriteLine("dotnet new3 current configuration:");
            Reporter.Output.WriteLine(" ");
            TableFormatter.Print(SettingsLoader.MountPoints, "(No Items)", "   ", '-', new Dictionary <string, Func <MountPointInfo, object> >
            {
                { "Mount Points", x => x.Place },
                { "Id", x => x.MountPointId },
                { "Parent", x => x.ParentMountPointId },
                { "Factory", x => x.MountPointFactoryId }
            });

            TableFormatter.Print(SettingsLoader.Components.OfType <IMountPointFactory>(), "(No Items)", "   ", '-', new Dictionary <string, Func <IMountPointFactory, object> >
            {
                { "Mount Point Factories", x => x.Id },
                { "Type", x => x.GetType().FullName },
                { "Assembly", x => x.GetType().GetTypeInfo().Assembly.FullName }
            });

            TableFormatter.Print(SettingsLoader.Components.OfType <IGenerator>(), "(No Items)", "   ", '-', new Dictionary <string, Func <IGenerator, object> >
            {
                { "Generators", x => x.Id },
                { "Type", x => x.GetType().FullName },
                { "Assembly", x => x.GetType().GetTypeInfo().Assembly.FullName }
            });
        }
Exemplo n.º 2
0
        private static void ListTemplates(CommandArgument template)
        {
            IEnumerable <ITemplateInfo> results = Microsoft.TemplateEngine.Edge.Template.TemplateCreator.List(template.Value);

            TableFormatter.Print(results, "(No Items)", "   ", '-', new Dictionary <string, Func <ITemplateInfo, object> >
            {
                { "Templates", x => x.Name },
                { "Short Names", x => $"[{x.ShortName}]" },
                { "Alias", x => AliasRegistry.GetAliasForTemplate(x) ?? "" }
            });
        }
Exemplo n.º 3
0
        private static void ListTemplates(CommandArgument template, CommandOption source)
        {
            IEnumerable <ITemplate> results = TemplateCreator.List(template.Value, source);

            TableFormatter.Print(results, "(No Items)", "   ", '-', new Dictionary <string, Func <ITemplate, string> >
            {
                { "Templates", x => x.Name },
                { "Short Names", x => $"[{x.ShortName}]" },
                { "Alias", x => AliasRegistry.GetAliasForTemplate(x) ?? "" }
            });
        }
Exemplo n.º 4
0
        private static void ShowConfig()
        {
            Reporter.Output.WriteLine("dotnet new3 current configuration:");
            Reporter.Output.WriteLine(" ");
            TableFormatter.Print(Broker.GetConfiguredSources(), "(No Items)", "   ", '-', new Dictionary <string, Func <IConfiguredTemplateSource, string> >
            {
                { "Template Sources", x => x.Location }
            });

            TableFormatter.Print(Broker.ComponentRegistry.OfType <ITemplateSource>(), "(No Items)", "   ", '-', new Dictionary <string, Func <ITemplateSource, string> >
            {
                { "Template Source Readers", x => x.Name },
                { "Assembly", x => x.GetType().GetTypeInfo().Assembly.FullName }
            });

            TableFormatter.Print(Broker.ComponentRegistry.OfType <IGenerator>(), "(No Items)", "   ", '-', new Dictionary <string, Func <IGenerator, string> >
            {
                { "Generators", x => x.Name },
                { "Assembly", x => x.GetType().GetTypeInfo().Assembly.FullName }
            });
        }
Exemplo n.º 5
0
        private static bool TryGetTemplate(string templateName, CommandOption source, bool quiet, out ITemplate tmplt, out IGenerator generator)
        {
            IReadOnlyList <IConfiguredTemplateSource> searchSources;

            if (!source.HasValue())
            {
                searchSources = Program.Broker.GetConfiguredSources().ToList();
            }
            else
            {
                IConfiguredTemplateSource realSource = Program.Broker.GetConfiguredSources().FirstOrDefault(x => x.Alias == source.Value());
                if (realSource == null)
                {
                    tmplt     = null;
                    generator = null;
                    return(false);
                }

                searchSources = new List <IConfiguredTemplateSource> {
                    realSource
                };
            }

            searchSources = ConfiguredTemplateSourceHelper.Scan(searchSources, Program.Broker.ComponentRegistry.OfType <ITemplateSource>());

            string aliasTemplateName = AliasRegistry.GetTemplateNameForAlias(templateName);

            generator = null;
            tmplt     = null;

            foreach (IGenerator gen in Program.Broker.ComponentRegistry.OfType <IGenerator>())
            {
                foreach (IConfiguredTemplateSource target in searchSources)
                {
                    if (gen.TryGetTemplateFromSource(target, templateName, out tmplt))
                    {
                        generator = gen;
                        break;
                    }

                    if (aliasTemplateName != null && gen.TryGetTemplateFromSource(target, aliasTemplateName, out tmplt))
                    {
                        generator = gen;
                        break;
                    }
                }

                if (generator != null)
                {
                    break;
                }
            }

            if (generator == null || tmplt == null)
            {
                List <ITemplate> results = List(templateName, source).ToList();

                if (results.Count == 0)
                {
                    if (!string.IsNullOrWhiteSpace(templateName) || source.HasValue())
                    {
                        Reporter.Error.WriteLine($"No template containing \"{templateName}\" was found in any of the configured sources.".Bold().Red());
                    }
                    else
                    {
                        TableFormatter.Print(results, "(No Items)", "   ", '-', new Dictionary <string, Func <ITemplate, string> >
                        {
                            { "#", x => "0." },
                            { "Templates", x => x.Name },
                            { "Short Names", x => $"[{x.ShortName}]" }
                        });
                    }

                    return(false);
                }

                int index;

                if (results.Count != 1 || string.IsNullOrWhiteSpace(templateName))
                {
                    int counter = 0;
                    TableFormatter.Print(results, "(No Items)", "   ", '-', new Dictionary <string, Func <ITemplate, string> >
                    {
                        { "#", x => $"{++counter}." },
                        { "Templates", x => x.Name },
                        { "Short Names", x => $"[{x.ShortName}]" }
                    });

                    Reporter.Output.WriteLine();
                    Reporter.Output.WriteLine("Select a template [1]:");

                    string key = Console.ReadLine();

                    if (string.IsNullOrWhiteSpace(key))
                    {
                        key = "1";
                    }

                    while (!int.TryParse(key, out index))
                    {
                        if (string.Equals(key, "q", StringComparison.OrdinalIgnoreCase))
                        {
                            return(false);
                        }

                        key = Console.ReadLine();
                    }
                }
                else
                {
                    if (!quiet)
                    {
                        Reporter.Output.WriteLine($"Using template: {results[0].Name} [{results[0].ShortName}] {AliasRegistry.GetAliasForTemplate(results[0])}");
                    }

                    index = 1;
                }

                tmplt     = results[index - 1];
                generator = results[index - 1].Generator;
            }

            return(true);
        }