Ejemplo n.º 1
0
        internal CliTemplateParameter(ITemplateParameter parameter, HostSpecificTemplateData data)
        {
            Name         = parameter.Name;
            Description  = parameter.Description ?? string.Empty;
            Type         = ParseType(parameter.DataType);
            DefaultValue = parameter.DefaultValue;
            DataType     = parameter.DataType;
            if (Type == ParameterType.Boolean && string.Equals(parameter.DefaultIfOptionWithoutValue, "true", StringComparison.OrdinalIgnoreCase))
            {
                //ignore, parser is doing this behavior by default
            }
            else
            {
                DefaultIfOptionWithoutValue = parameter.DefaultIfOptionWithoutValue;
            }
            IsRequired          = parameter.Priority == TemplateParameterPriority.Required && parameter.DefaultValue == null;
            IsHidden            = parameter.Priority == TemplateParameterPriority.Implicit || data.HiddenParameterNames.Contains(parameter.Name);
            AlwaysShow          = data.ParametersToAlwaysShow.Contains(parameter.Name);
            AllowMultipleValues = parameter.AllowMultipleValues;

            if (data.ShortNameOverrides.ContainsKey(parameter.Name))
            {
                _shortNameOverrides.Add(data.ShortNameOverrides[parameter.Name]);
            }
            if (data.LongNameOverrides.ContainsKey(parameter.Name))
            {
                _longNameOverrides.Add(data.LongNameOverrides[parameter.Name]);
            }
        }
Ejemplo n.º 2
0
        private void GenerateUsageForTemplate(ITemplateInfo templateInfo)
        {
            ITemplate                template         = EnvironmentSettings.SettingsLoader.LoadTemplate(templateInfo);
            IParameterSet            allParams        = template.Generator.GetParametersForTemplate(EnvironmentSettings, template);
            HostSpecificTemplateData hostTemplateData = ReadHostSpecificTemplateData(template);

            Reporter.Output.Write($"    dotnet {CommandName} {template.ShortName}");
            IEnumerable <ITemplateParameter> filteredParams = FilterParamsForHelp(allParams, hostTemplateData.HiddenParameterNames);

            foreach (ITemplateParameter parameter in filteredParams)
            {
                if (string.Equals(parameter.DataType, "bool", StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(parameter.DefaultValue, "false", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                string displayParameter = hostTemplateData.DisplayNameForParameter(parameter.Name);

                Reporter.Output.Write($" --{displayParameter}");

                if (!string.IsNullOrEmpty(parameter.DefaultValue) && !string.Equals(parameter.DataType, "bool", StringComparison.OrdinalIgnoreCase))
                {
                    Reporter.Output.Write($" {parameter.DefaultValue}");
                }
            }

            Reporter.Output.WriteLine();
        }
Ejemplo n.º 3
0
        private void ParseTemplateArgs(ITemplateInfo templateInfo)
        {
            ITemplate     template  = EnvironmentSettings.SettingsLoader.LoadTemplate(templateInfo);
            IParameterSet allParams = template.Generator.GetParametersForTemplate(EnvironmentSettings, template);

            _hostSpecificTemplateData = ReadHostSpecificTemplateData(template);
            _app.SetupTemplateParameters(allParams, _hostSpecificTemplateData.LongNameOverrides, _hostSpecificTemplateData.ShortNameOverrides);

            // re-parse after setting up the template params
            _app.ParseArgs(_app.InternalParamValueList("--extra-args"));
        }
Ejemplo n.º 4
0
 internal ChoiceTemplateParameter(ITemplateParameter parameter, HostSpecificTemplateData data) : base(parameter, data)
 {
     if (!parameter.IsChoice())
     {
         throw new ArgumentException($"{nameof(parameter)} should have {nameof(parameter.Type)} {nameof(ParameterType.Choice)}");
     }
     if (parameter.Choices == null)
     {
         throw new ArgumentException($"{nameof(parameter)} should have {nameof(parameter.Choices)}");
     }
     _choices = parameter.Choices.ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.OrdinalIgnoreCase);
 }
Ejemplo n.º 5
0
        private static bool IsTemplateHiddenByHostFile(ITemplateInfo templateInfo, IHostSpecificDataLoader hostDataLoader)
        {
            HostSpecificTemplateData hostData = hostDataLoader.ReadHostSpecificTemplateData(templateInfo);

            return(hostData.IsHidden);
        }
Ejemplo n.º 6
0
        public static void ParseTemplateArgs(ITemplateInfo templateInfo, IHostSpecificDataLoader hostDataLoader, INewCommandInput commandInput)
        {
            HostSpecificTemplateData hostData = hostDataLoader.ReadHostSpecificTemplateData(templateInfo);

            commandInput.ReparseForTemplate(templateInfo, hostData);
        }
Ejemplo n.º 7
0
 internal CliTemplateInfo(ITemplateInfo templateInfo, HostSpecificTemplateData cliData)
 {
     _templateInfo = templateInfo ?? throw new ArgumentNullException(nameof(templateInfo));
     _cliData      = cliData ?? throw new ArgumentNullException(nameof(cliData));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Checks if the template is hidden by host specific template settings.
        /// </summary>
        internal static bool IsHiddenByHostFile(this ITemplateInfo template, IHostSpecificDataLoader hostSpecificDataLoader)
        {
            HostSpecificTemplateData hostData = hostSpecificDataLoader.ReadHostSpecificTemplateData(template);

            return(hostData.IsHidden);
        }