Beispiel #1
0
        private static int ValidateSchema(ValidateCommandLineParameters parameters)
        {
            if (!ValidateParameters(parameters))
            {
                return(1);
            }

            var schemaPath = Path.GetFullPath(parameters.SchemaPath);

            WriteMessage($"Validating configuration file JSON schema at '{schemaPath}'");

            if (!File.Exists(schemaPath))
            {
                WriteError($"ERROR: Schema file at '{schemaPath}' does not exist");
                return(1);
            }

            var expectedSchema = GetSchema();
            var actualSchema   = File.ReadAllText(schemaPath);

            if (!StringComparer.Ordinal.Equals(expectedSchema, actualSchema))
            {
                WriteError("ERROR: Schema file differs from expected schema");
                return(1);
            }

            return(0);
        }
Beispiel #2
0
        private static int ValidateDocs(ValidateCommandLineParameters parameters)
        {
            if (!ValidateParameters(parameters))
            {
                return(1);
            }

            var success = true;

            var resultsTable = new Table()
                               .Border(TableBorder.Square)
                               .BorderColor(Color.White)
                               .AddColumn(new TableColumn("[u]File[/]").LeftAligned())
                               .AddColumn(new TableColumn("[u]Result[/]").LeftAligned())
                               .AddColumn(new TableColumn("[u]LineNumber[/]").LeftAligned())
                               .AddColumn(new TableColumn("[u]RuleId[/]").LeftAligned())
                               .AddColumn(new TableColumn("[u]Message[/]").LeftAligned());


            foreach (var path in GetAllInputFiles(parameters))
            {
                var outputPath = Path.ChangeExtension(path, "").TrimEnd('.');

                var result = DocsValidator.ValidateDocument(path);
                success &= result.Success;

                if (result.Success)
                {
                    resultsTable.AddRow(
                        $"[green]{path}[/]",
                        "[green]Success[/]"
                        );
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        resultsTable.AddRow(
                            $"[red]{path}[/]",
                            "[red]Error[/]",
                            $"{(error.LineNumber > 0 ? error.LineNumber.ToString() : "")}",
                            $"{error.RuleId}",
                            $"{error.Message}"
                            );
                    }
                }
            }

            AnsiConsole.Write(resultsTable);
            return(success ? 0 : 1);
        }