Exemplo n.º 1
0
        public static int Complete(string[] args, [CanBeNull] string rootDirectory, [CanBeNull] string buildScript)
        {
            var words = args.Single();

            if (!words.StartsWithOrdinalIgnoreCase(c_commandName))
            {
                return(0);
            }

            words = words.Substring(c_commandName.Length).TrimStart();

            if (rootDirectory == null)
            {
                // TODO: parse --root parameter
                return(0);
            }

            var completionFile = Constants.GetCompletionFile((AbsolutePath)rootDirectory);

            if (!File.Exists(completionFile))
            {
                Build(buildScript.NotNull(), $"--{Constants.CompletionParameterName}");
                return(1);
            }

            var position        = EnvironmentInfo.GetParameter <int?>("position");
            var completionItems = SerializationTasks.YamlDeserializeFromFile <Dictionary <string, string[]> >(completionFile);

            foreach (var item in CompletionUtility.GetRelevantCompletionItems(words, completionItems))
            {
                Console.WriteLine(item);
            }

            return(0);
        }
Exemplo n.º 2
0
        public void TestGetRelevantCompletionItems(string words, string[] expectedItems)
        {
            var completionItems =
                new Dictionary <string, string[]>
            {
                { Constants.InvokedTargetsParameterName, new[] { "Compile", "Pack" } },
                { "ApiKey", null },
                { "NuGetSource", null }
            };

            CompletionUtility.GetRelevantCompletionItems(words, completionItems)
            .Should()
            .BeEquivalentTo(expectedItems);
        }
Exemplo n.º 3
0
        public static int Complete(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
        {
            if (rootDirectory == null)
            {
                return(0);
            }

            var words = args.Single();

            if (!words.StartsWithOrdinalIgnoreCase(CommandName))
            {
                return(0);
            }

            words = words.Substring(CommandName.Length).TrimStart();

            var buildSchemaFile = GetBuildSchemaFile(rootDirectory);
            var completionFile  = GetCompletionFile(rootDirectory);

            if (!File.Exists(buildSchemaFile) && !File.Exists(completionFile))
            {
                Build(buildScript.NotNull(), $"--{CompletionParameterName}");
                return(1);
            }

            var position        = EnvironmentInfo.GetParameter <int?>("position");
            var completionItems = IsLegacy(rootDirectory)
                ? SerializationTasks.YamlDeserializeFromFile <Dictionary <string, string[]> >(completionFile)
                : SchemaUtility.GetCompletionItems(buildSchemaFile, GetProfileNames(rootDirectory));

            foreach (var item in CompletionUtility.GetRelevantCompletionItems(words, completionItems))
            {
                Console.WriteLine(item);
            }

            return(0);
        }
Exemplo n.º 4
0
        public void OnBuildCreated(NukeBuild build, IReadOnlyCollection <ExecutableTarget> executableTargets)
        {
            if (BuildServerConfigurationGeneration.IsActive)
            {
                return;
            }

            if (IsLegacy(NukeBuild.RootDirectory))
            {
                WriteCompletionFile(build);
            }
            else if (NukeBuild.BuildProjectFile != null)
            {
                SchemaUtility.WriteBuildSchemaFile(build);
                SchemaUtility.WriteDefaultParametersFile();
            }
            else if (EnvironmentInfo.GetPositionalArgument <string>(0) == ":complete")
            {
                var schema          = SchemaUtility.GetBuildSchema(build);
                var profileNames    = GetProfileNames(NukeBuild.RootDirectory);
                var completionItems = SchemaUtility.GetCompletionItems(schema, profileNames);

                var words = EnvironmentInfo.CommandLineArguments.Skip(2).JoinSpace();
                var relevantCompletionItems = CompletionUtility.GetRelevantCompletionItems(words, completionItems);
                foreach (var item in relevantCompletionItems)
                {
                    Console.WriteLine(item);
                }

                Environment.Exit(exitCode: 0);
            }

            if (EnvironmentInfo.GetParameter <bool>(CompletionParameterName))
            {
                Environment.Exit(exitCode: 0);
            }
        }