Ejemplo n.º 1
0
        public IEnumerable <CommandDefinition> GetCommands(IEnumerable <string> context)
        {
            context = context.ToArray();
            if (!context.Any())
            {
                newCommand = CommandDefinitionBuilder.Create()
                             .SetName("new")
                             .SetHelp("Creates new files / projects.")
                             .Build();
                deployCommand = templateCommandBuilder.GenerateDeployCommandDefinition(null, null, null, repository.Templates.ToArray());
                return(new[] { newCommand, deployCommand });
            }

            if (context.SequenceEqual(new[] { "new" }))
            {
                List <CommandDefinition> commandDefinitions = new List <CommandDefinition>();
                foreach (TemplateDescription template in repository.Templates)
                {
                    if (template.isHidden || commandDefinitions.Any(d => d.Name == template.name))
                    {
                        continue;
                    }
                    Entity templateEntity = entityFactory.Create(template.name);
                    templateEntity.SetMetaData(true, EntityKeys.IsTemplateOnly);
                    commandDefinitions.Add(templateCommandBuilder.GenerateNewCommandDefinition(templateEntity, template, newCommand, repository.Templates));
                }
                return(commandDefinitions);
            }

            if (context.SequenceEqual(new[] { "deploy" }))
            {
                List <CommandDefinition> commandDefinitions = new List <CommandDefinition>();
                foreach (TemplateDescription template in repository.Templates)
                {
                    if (template.isHidden ||
                        commandDefinitions.Any(d => d.Name == template.name) ||
                        !template.isRoot)
                    {
                        continue;
                    }
                    Entity templateEntity = entityFactory.Create(template.name);
                    templateEntity.SetMetaData(true, EntityKeys.IsTemplateOnly);
                    commandDefinitions.Add(templateCommandBuilder.GenerateDeployCommandDefinition(templateEntity,
                                                                                                  template,
                                                                                                  deployCommand,
                                                                                                  repository.Templates.ToArray()));
                }
                return(commandDefinitions);
            }

            if (context.SequenceEqual(new[] { "generate" }))
            {
                return(templateCommandBuilder.CreateGenerateCommandDefinitions(generateCommands, repository.Templates));
            }

            return(Enumerable.Empty <CommandDefinition>());
        }
        public IEnumerable <CommandDefinition> GetCommands(IEnumerable <string> context)
        {
            context = context.ToArray();
            if (!context.Any())
            {
                newCommand = CommandDefinitionBuilder.Create()
                             .SetName("new")
                             .SetHelp("Creates new files / projects.")
                             .Build();
                deployCommand = templateCommandBuilder.GenerateDeployCommandDefinition(null, null, null, repository.Templates.ToArray());
                return(new[] { newCommand, deployCommand });
            }

            if (context.SequenceEqual(new[] { "new" }))
            {
                List <CommandDefinition> commandDefinitions = new List <CommandDefinition>();
                foreach (TemplateDescription template in repository.Templates)
                {
                    if (template.isHidden || commandDefinitions.Any(d => d.Name == template.name))
                    {
                        continue;
                    }
                    Entity templateEntity = entityFactory.Create(template.name);
                    templateEntity.SetMetaData(true, EntityKeys.IsTemplateOnly);
                    commandDefinitions.Add(templateCommandBuilder.GenerateNewCommandDefinition(templateEntity, template, newCommand, repository.Templates));
                }
                return(commandDefinitions);
            }

            if (context.SequenceEqual(new[] { "deploy" }))
            {
                List <CommandDefinition> commandDefinitions = new List <CommandDefinition>();
                foreach (TemplateDescription template in repository.Templates)
                {
                    if (template.isHidden ||
                        commandDefinitions.Any(d => d.Name == template.name) ||
                        !template.isRoot)
                    {
                        continue;
                    }
                    Entity templateEntity = entityFactory.Create(template.name);
                    templateEntity.SetMetaData(true, EntityKeys.IsTemplateOnly);
                    commandDefinitions.Add(templateCommandBuilder.GenerateDeployCommandDefinition(templateEntity,
                                                                                                  template,
                                                                                                  deployCommand,
                                                                                                  repository.Templates.ToArray()));
                }
                return(commandDefinitions);
            }

            if (context.SequenceEqual(new[] { "generate" }))
            {
                return(CreateGenerateCommands());
            }

            return(Enumerable.Empty <CommandDefinition>());

            IEnumerable <CommandDefinition> CreateGenerateCommands()
            {
                HashSet <string> generators = new HashSet <string>();

                foreach (TemplateDescription template in repository.Templates)
                {
                    if (template.isHidden)
                    {
                        continue;
                    }

                    foreach (string generator in (template.GeneratedFile ?? Enumerable.Empty <templateGeneratedFile>())
                             .Select(g => g.generator.ToLowerInvariant()))
                    {
                        generators.Add(generator);
                    }
                }

                generateCommands.Clear();
                foreach (string generator in generators)
                {
                    generateCommands.Add(AddArguments(CommandDefinitionBuilder.Create()
                                                      .SetName(generator)
                                                      .SetHelp($"Generates all files with the '{generator}' generator.")
                                                      .AddExample($"generate {generator} --{EntityKeys.PathKey} Path/To/Project",
                                                                  $"generate all {generator} files in default location."))
                                         );
                }

                generateCommands.Add(AddArguments(CommandDefinitionBuilder.Create()
                                                  .SetName("all")
                                                  .SetHelp($"Generates all files.")
                                                  .AddExample($"generate all --{EntityKeys.PathKey} Path/To/Project",
                                                              $"generate all files in default location."))
                                     );

                return(generateCommands);

                CommandDefinition AddArguments(CommandDefinitionBuilder definitionBuilder)
                {
                    return(definitionBuilder.CreateArgument()
                           .SetName(EntityKeys.PathKey)
                           .SetShortName('p')
                           .SetHelp(
                               "The path to the project settings file or the project root directory. " +
                               "Default is the current directory.")
                           .SetArgumentType(ArgumentType.SingleValue)
                           .Build()
                           .CreateArgument()
                           .SetName(EntityKeys.SourceDirectoryKey)
                           .SetShortName('s')
                           .SetHelp(
                               "The path of the source directories separated by ','. Default is the 'src' directory " +
                               "if such a directory exists. If not, the directory " +
                               "defined with the '--path' option is used. Relative paths are relative " +
                               "to the directory defined with the '--path' option. If any path contains a ' ' quotation " +
                               "marks should be used around all paths, e.g. \"path1,path With Space,path2\".")
                           .SetArgumentType(ArgumentType.MultipleValue)
                           .Build()
                           .CreateArgument()
                           .SetName(EntityKeys.IncludeDirectoryKey)
                           .SetShortName('i')
                           .SetHelp(
                               "Overrides the includes used to find header files. Usually CMake is used to determine " +
                               "the include paths. If that is not possible or wanted the value of this argument is " +
                               "used instead of the CMake determined include paths. Relative paths are relative " +
                               "to the directory defined with the '--path' option. If any path contains a ' ' quotation " +
                               "marks should be used around all paths, e.g. \"path1,path With Space,path2\". Additionally " +
                               "to these paths the include paths determined by the SDK will always be considered and " +
                               "do not need to be specified additionally.")
                           .SetArgumentType(ArgumentType.MultipleValue)
                           .Build()
                           .CreateArgument()
                           .SetName(Constants.NoIncludePathDetection)
                           .SetShortName('n')
                           .SetHelp("Disables the automatic include path detection using CMake. This option is not necessary if the " +
                                    $"'-{EntityKeys.IncludeDirectoryKey}' option is used, as that option will automatically disable " +
                                    "the CMake detection. The system paths defined by the SDK are still used.")
                           .SetArgumentType(ArgumentType.Bool)
                           .Build()
                           .CreateArgument()
                           .SetName(Constants.OutputArgumentName)
                           .SetShortName('o')
                           .SetHelp("The path where the files will be generated in. " +
                                    "Default is the 'intermediate' directory. Relative paths are relative " +
                                    "to the directory defined with the '--path' option.")
                           .SetArgumentType(ArgumentType.SingleValue)
                           .Build()
                           .Build());
                }
            }
        }