public NewCommandInputCli(string commandName) { _commandName = commandName; _noTemplateCommand = CommandParserSupport.CreateNewCommandWithoutTemplateInfo(_commandName); _currentCommand = _noTemplateCommand; ExpandedExtraArgsFiles = false; }
public int Execute(params string[] args) { _args = args; ParseArgs(); bool needsReparse = false; if (ExtraArgsFileNames != null && ExtraArgsFileNames.Count > 0) { // add the extra args to the _args and force a reparse // This cannot adjust the template name, so no need to re-check here. IReadOnlyList <string> extraArgs = AppExtensions.CreateArgListFromAdditionalFiles(ExtraArgsFileNames); List <string> allArgs = RemoveExtraArgsTokens(_args); allArgs.AddRange(extraArgs); _args = allArgs; needsReparse = true; ExpandedExtraArgsFiles = true; } if (string.IsNullOrEmpty(_templateNameArg)) { _currentCommand = CommandParserSupport.CreateNewCommandForNoTemplateName(_commandName); needsReparse = true; } if (needsReparse) { ParseArgs(); } return(_invoke.Invoke().Result); }
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); } }
public int Execute(params string[] args) { _args = args; ParseArgs(); bool needsReparse = false; if (ExtraArgsFileNames != null && ExtraArgsFileNames.Count > 0) { // add the extra args to the _args and force a reparse IReadOnlyList <string> extraArgs = AppExtensions.CreateArgListFromAdditionalFiles(ExtraArgsFileNames); List <string> allArgs = new List <string>(_args); allArgs.AddRange(extraArgs); _args = allArgs; needsReparse = true; } IList <string> templateNameList = _parseResult.GetArgumentListAtPath(new[] { _commandName }).ToList(); if ((templateNameList.Count > 0) && !templateNameList[0].StartsWith("-", StringComparison.Ordinal) && (_parseResult.Tokens.Count >= 2) && string.Equals(templateNameList[0], _parseResult.Tokens.ElementAt(1), StringComparison.Ordinal)) { _templateNameArg = templateNameList[0]; } else { _templateNameArg = string.Empty; _currentCommand = CommandParserSupport.CreateNewCommandForNoTemplateName(_commandName); needsReparse = true; } if (needsReparse) { ParseArgs(); } return(_invoke.Invoke().Result); }
public NewCommandInputCli(string commandName) { _commandName = commandName; _noTemplateCommand = CommandParserSupport.CreateNewCommandWithoutTemplateInfo(_commandName); _currentCommand = _noTemplateCommand; }