Exemplo n.º 1
0
        public void TestGetCompletionItemsFromSchema()
        {
            var schema       = JObject.Parse(@"
{
  ""$schema"": ""http://json-schema.org/draft-04/schema#"",
  ""title"": ""Build Schema"",
  ""definitions"": {
    ""build"": {
      ""type"": ""object"",
      ""properties"": {
        ""NoLogo"": {
          ""type"": ""boolean"",
          ""description"": ""Disables displaying the NUKE logo""
        },
        ""Configuration"": {
          ""type"": ""string"",
          ""description"": ""Configuration to build - Default is 'Debug' (local) or 'Release' (server)"",
          ""enum"": [
            ""Debug"",
            ""Release""
          ]
        },
        ""Target"": {
          ""type"": ""array"",
          ""description"": ""List of targets to be invoked. Default is '{default_target}'"",
          ""items"": {
            ""type"": ""string"",
            ""enum"": [
              ""Restore"",
              ""Compile""
            ]
          }
        }
      }
    }
  }
}
");
            var profileNames = new[] { "dev" };
            var items        = SchemaUtility.GetCompletionItems(schema, profileNames);

            items.Should().BeEquivalentTo(
                new Dictionary <string, string[]>
            {
                ["NoLogo"]        = null,
                ["Configuration"] = new[] { "Debug", "Release" },
                ["Target"]        = new[] { "Restore", "Compile" },
                [Constants.LoadedLocalProfilesParameterName] = profileNames
            });
        }
Exemplo n.º 2
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);
        }