コード例 #1
0
        internal static TemplateResult FromParseResult(TemplateCommand templateCommand, ParseResult parseResult)
        {
            TemplateResult result = new TemplateResult(templateCommand, parseResult);

            result.IsLanguageMatch = templateCommand.LanguageOption == null || !parseResult.HasErrorFor(templateCommand.LanguageOption);
            result.IsTypeMatch     = templateCommand.TypeOption == null || !parseResult.HasErrorFor(templateCommand.TypeOption);
            result.IsBaselineMatch = templateCommand.BaselineOption == null || !parseResult.HasErrorFor(templateCommand.BaselineOption);
            foreach (var option in templateCommand.TemplateOptions)
            {
                if (parseResult.HasErrorFor(option.Value.Option))
                {
                    result._parametersInfo.Add(InvalidTemplateOptionResult.FromParseResult(option.Value, parseResult));
                }
                else
                {
                    if (TemplateOptionResult.FromParseResult(option.Value, parseResult) is TemplateOptionResult {
                    } res)
                    {
                        result._parametersInfo.Add(res);
                    }
                }
            }
            foreach (var unmatchedToken in parseResult.UnmatchedTokens)
            {
                result._parametersInfo.Add(new InvalidTemplateOptionResult(
                                               null,
                                               InvalidTemplateOptionResult.Kind.InvalidName,
                                               inputFormat: unmatchedToken,
                                               specifiedValue: null,
                                               errorMessage: null));
            }
            return(result);
        }
コード例 #2
0
        internal static void ShowCommandOptions(
            IEnumerable <TemplateCommand> templatesToShow,
            TemplateCommand preferredTemplate,
            HelpContext context)
        {
            List <Option> optionsToShow = new List <Option>()
            {
                preferredTemplate.NameOption,
                preferredTemplate.OutputOption,
                preferredTemplate.DryRunOption,
                TemplateCommand.ForceOption,
                preferredTemplate.NoUpdateCheckOption
            };

            foreach (var template in templatesToShow)
            {
                if (template.LanguageOption != null)
                {
                    optionsToShow.Add(template.LanguageOption);
                    break;
                }
            }
            foreach (var template in templatesToShow)
            {
                if (template.TypeOption != null)
                {
                    optionsToShow.Add(template.TypeOption);
                    break;
                }
            }
            foreach (var template in templatesToShow)
            {
                if (template.AllowScriptsOption != null)
                {
                    optionsToShow.Add(template.AllowScriptsOption);
                    break;
                }
            }

            context.Output.WriteLine(context.HelpBuilder.LocalizationResources.HelpOptionsTitle());
            IEnumerable <TwoColumnHelpRow> optionsToWrite = optionsToShow.Select(o => context.HelpBuilder.GetTwoColumnRow(o, context));

            context.HelpBuilder.WriteColumns(optionsToWrite.ToArray(), context);
            context.Output.WriteLine();
        }
コード例 #3
0
        internal static IEnumerable <CompletionItem> GetTemplateCompletions(
            InstantiateCommandArgs args,
            IEnumerable <TemplateGroup> templateGroups,
            IEngineEnvironmentSettings environmentSettings,
            TemplatePackageManager templatePackageManager,
            TextCompletionContext context)
        {
            HashSet <CompletionItem>  distinctCompletions = new HashSet <CompletionItem>();
            TemplateConstraintManager constraintManager   = new TemplateConstraintManager(environmentSettings);

            foreach (TemplateGroup templateGroup in templateGroups.Where(template => template.ShortNames.Contains(args.ShortName)))
            {
                foreach (IGrouping <int, CliTemplateInfo> templateGrouping in GetAllowedTemplates(constraintManager, templateGroup).GroupBy(g => g.Precedence).OrderByDescending(g => g.Key))
                {
                    foreach (CliTemplateInfo template in templateGrouping)
                    {
                        try
                        {
                            TemplateCommand command = new TemplateCommand(
                                args.Command,
                                environmentSettings,
                                templatePackageManager,
                                templateGroup,
                                template);

                            Parser parser = ParserFactory.CreateParser(command);

                            //it is important to pass raw text to get the completion
                            //completions for args passed as array are not supported
                            ParseResult parseResult = parser.Parse(context.CommandLineText);
                            foreach (CompletionItem completion in parseResult.GetCompletions(context.CursorPosition))
                            {
                                distinctCompletions.Add(completion);
                            }
                        }
                        catch (InvalidTemplateParametersException e)
                        {
                            Reporter.Error.WriteLine(string.Format(LocalizableStrings.GenericWarning, e.Message));
                        }
                    }
                }
            }
            return(distinctCompletions.OrderBy(c => c.Label, StringComparer.OrdinalIgnoreCase));
        }
コード例 #4
0
        public TemplateCommandArgs(TemplateCommand command, BaseCommand parentCommand, ParseResult parseResult)
        {
            ParseResult   = parseResult ?? throw new ArgumentNullException(nameof(parseResult));
            _command      = command ?? throw new ArgumentNullException(nameof(command));
            ParentCommand = parentCommand ?? throw new ArgumentNullException(nameof(parentCommand));
            RootCommand   = GetRootCommand(parentCommand);

            Name                 = parseResult.GetValueForOptionOrNull(command.NameOption);
            OutputPath           = parseResult.GetValueForOptionOrNull(command.OutputOption);
            IsForceFlagSpecified = parseResult.GetValueForOption(TemplateCommand.ForceOption);
            IsDryRun             = parseResult.GetValueForOption(command.DryRunOption);
            NoUpdateCheck        = parseResult.GetValueForOption(command.NoUpdateCheckOption);

            if (command.LanguageOption != null)
            {
                Language = parseResult.GetValueForOptionOrNull(command.LanguageOption);
            }
            if (command.TypeOption != null)
            {
                Type = parseResult.GetValueForOptionOrNull(command.TypeOption);
            }
            if (command.BaselineOption != null)
            {
                BaselineName = parseResult.GetValueForOptionOrNull(command.BaselineOption);
            }
            if (command.AllowScriptsOption != null)
            {
                AllowScripts = parseResult.GetValueForOption(command.AllowScriptsOption);
            }

            foreach (var opt in command.TemplateOptions)
            {
                if (parseResult.FindResultFor(opt.Value.Option) is { } result)
                {
                    _templateOptions[opt.Key] = result;
                }
            }
            Template = command.Template;
        }
コード例 #5
0
 private TemplateResult(TemplateCommand templateCommand, ParseResult parseResult)
 {
     _templateCommand = templateCommand;
     _parseResult     = parseResult;
 }