示例#1
0
        private static void HandleCompletion(NukeBuild build)
        {
            var completionItems = new SortedDictionary <string, string[]>();

            var targetNames = build.TargetDefinitions.Select(x => x.Name).OrderBy(x => x).ToList();

            completionItems[NukeBuild.InvokedTargetsParameterName] = targetNames.ToArray();
            completionItems[NukeBuild.SkippedTargetsParameterName] = targetNames.ToArray();

            string[] GetSubItems(Type type)
            {
                if (type.IsEnum)
                {
                    return(type.GetEnumNames());
                }
                if (type.IsSubclassOf(typeof(Enumeration)))
                {
                    return(type.GetFields(ReflectionService.Static).Select(x => x.Name).ToArray());
                }
                return(null);
            }

            foreach (var parameter in build.GetParameterMembers())
            {
                var parameterName = ParameterService.Instance.GetParameterName(parameter);
                if (completionItems.ContainsKey(parameterName))
                {
                    continue;
                }

                completionItems[parameterName] = GetSubItems(parameter.GetFieldOrPropertyType())?.OrderBy(x => x).ToArray();
            }

            SerializationTasks.YamlSerializeToFile(completionItems, NukeBuild.CompletionFile);

            if (EnvironmentInfo.ParameterSwitch(NukeBuild.CompletionParameterName))
            {
                Environment.Exit(exitCode: 0);
            }
        }