Esempio n. 1
0
        public override string GetHelpText(string commandName = null)
        {
            string        helpText = base.GetHelpText(commandName);
            StringBuilder sb       = new StringBuilder();

            // Search for NuGetPackages with CodeGenerationPackages.
            if (ProjectContext != null)
            {
                var nuGetPackages         = ProjectContext.PackageDependencies.Select(d => d.Path);
                var paramDefinitionsCache = BuildParamDefinitionCache(nuGetPackages);

                if (!string.IsNullOrEmpty(GeneratorArgument.Value))
                {
                    sb.AppendLine();
                    sb.AppendLine(string.Format(Resources.SelectedCodeGeneratorStr, GeneratorArgument.Value));
                    ParamDefinition generatorParamDef = null;
                    if (paramDefinitionsCache.TryGetValue(GeneratorArgument.Value, out generatorParamDef))
                    {
                        sb.AppendLine(BuildHelpForGenerator(generatorParamDef));
                    }
                    else
                    {
                        // Generator not available.
                        sb.AppendLine(string.Format(Resources.NoCodeGeneratorFound, GeneratorArgument.Value));
                        sb.AppendLine(GetHelpTextForAvailableGenerators(paramDefinitionsCache));
                    }
                }
                else
                {
                    sb.AppendLine(GetHelpTextForAvailableGenerators(paramDefinitionsCache));
                }

                sb.Insert(0, helpText);
            }
            else
            {
                Debug.Fail("Project Context was not set. Cannot search for generators to display help.");
            }

            return(sb.ToString());
        }
Esempio n. 2
0
        private static string BuildHelpForGenerator(ParamDefinition generatorParamDef)
        {
            StringBuilder sb = new StringBuilder();

            if (generatorParamDef.Arguments != null && generatorParamDef.Arguments.Any())
            {
                sb.AppendLine();
                sb.AppendLine(Resources.GeneratorArgsHeader);
                var maxLenArgument = generatorParamDef.Arguments.Max(a => a.Name.Length);
                var formatStr      = "  {0,-" + maxLenArgument + "} : {1}";
                foreach (var arg in generatorParamDef.Arguments)
                {
                    sb.AppendLine(string.Format(formatStr, arg.Name, arg.Description));
                }
            }

            if (generatorParamDef.Options != null && generatorParamDef.Options.Any())
            {
                sb.AppendLine();
                sb.AppendLine(Resources.GeneratorOptionsHeader);
                var maxLenOption = generatorParamDef.Options.Max(o => o.Name.Length + o.ShortName.Length) + 4;
                var formatStr    = "  {0,-" + maxLenOption + "} : {1}";

                foreach (var opt in generatorParamDef.Options)
                {
                    if (string.IsNullOrEmpty(opt.ShortName))
                    {
                        sb.AppendLine(string.Format(formatStr, "--" + opt.Name, opt.Description));
                    }
                    else
                    {
                        sb.AppendLine(string.Format(formatStr, "--" + opt.Name + "|-" + opt.ShortName, opt.Description));
                    }
                }
            }

            return(sb.ToString());
        }