Exemple #1
0
        public void ReparseForTemplate(ITemplateInfo templateInfo, HostSpecificTemplateData hostSpecificTemplateData)
        {
            // The params getting filtered out are "standard" to dotnet new - they get explicitly setup in the command
            //      and their flags cannot be overridden by host specific configuration.
            // type & language: These are "tags" in template.json, which become params in the templateInfo object.
            // name: Gets added as a param in SimpleConfigModel - to facilitate the built in value forms for name.
            //       name can also be explicitly specified in the template.json - for custom value forms on name.
            List <ITemplateParameter> filteredParams = templateInfo.Parameters.Where(x => !string.Equals(x.Name, "type", StringComparison.OrdinalIgnoreCase) &&
                                                                                     !string.Equals(x.Name, "language", StringComparison.OrdinalIgnoreCase) &&
                                                                                     !string.Equals(x.Name, "name", StringComparison.OrdinalIgnoreCase))
                                                       .ToList();
            Command _templateSpecificCommand;

            try
            {
                _templateSpecificCommand = CommandParserSupport.CreateNewCommandWithArgsForTemplate(
                    _commandName,
                    _templateNameArg,
                    filteredParams,
                    hostSpecificTemplateData.LongNameOverrides,
                    hostSpecificTemplateData.ShortNameOverrides,
                    out IReadOnlyDictionary <string, IReadOnlyList <string> > templateParamMap);

                _currentCommand = _templateSpecificCommand;
                ParseArgs();

                // this must happen after ParseArgs(), which resets _templateParamCanonicalToVariantMap
                _templateParamCanonicalToVariantMap = templateParamMap;

                Dictionary <string, string> templateParamValues = new Dictionary <string, string>();

                foreach (KeyValuePair <string, IReadOnlyList <string> > paramInfo in _templateParamCanonicalToVariantMap)
                {
                    string paramName    = paramInfo.Key;
                    string firstVariant = paramInfo.Value[0];

                    // This returns true if the arg was specified, irrespective of whether it has a value.
                    // If the arg was specified, it goes in the list.
                    // Null valued args are important - they facilitate bools & other value-optional args.
                    if (_parseResult.TryGetArgumentValueAtPath(out string argValue, new[] { _commandName, firstVariant }))
                    {
                        templateParamValues.Add(paramName, argValue);
                    }
                }

                _templateParamValues = templateParamValues;
            }
            catch (Exception ex)
            {
                throw new CommandParserException("Error parsing input parameters", string.Join(" ", _args), ex);
            }
        }
        public void ReparseForTemplate(ITemplateInfo templateInfo, HostSpecificTemplateData hostSpecificTemplateData)
        {
            List <ITemplateParameter> filteredParams = templateInfo.Parameters.Where(x => !string.Equals(x.Name, "type", StringComparison.OrdinalIgnoreCase) &&
                                                                                     !string.Equals(x.Name, "language", StringComparison.OrdinalIgnoreCase))
                                                       .ToList();
            Command _templateSpecificCommand;

            try
            {
                _templateSpecificCommand = CommandParserSupport.CreateNewCommandWithArgsForTemplate(
                    _commandName,
                    _templateNameArg,
                    filteredParams,
                    hostSpecificTemplateData.LongNameOverrides,
                    hostSpecificTemplateData.ShortNameOverrides,
                    out IReadOnlyDictionary <string, IReadOnlyList <string> > templateParamMap);

                _currentCommand = _templateSpecificCommand;
                ParseArgs();

                // this must happen after ParseArgs(), which resets _templateParamCanonicalToVariantMap
                _templateParamCanonicalToVariantMap = templateParamMap;

                Dictionary <string, string> templateParamValues = new Dictionary <string, string>();

                foreach (KeyValuePair <string, IReadOnlyList <string> > paramInfo in _templateParamCanonicalToVariantMap)
                {
                    string paramName    = paramInfo.Key;
                    string firstVariant = paramInfo.Value[0];

                    // This returns true if the arg was specified, irrespective of whether it has a value.
                    // If the arg was specified, it goes in the list.
                    // Null valued args are important - they facilitate bools & other value-optional args.
                    if (_parseResult.TryGetArgumentValueAtPath(out string argValue, new[] { _commandName, firstVariant }))
                    {
                        templateParamValues.Add(paramName, argValue);
                    }
                }

                _templateParamValues = templateParamValues;
            }
            catch (Exception ex)
            {
                throw new CommandParserException("Error parsing input parameters", string.Join(" ", _args), ex);
            }
        }