<commit_before>﻿// Copyright (c) 2017 Colectica. All rights reserved
// See the LICENSE file in the project root for more information.
using Cogs.Common;
using Cogs.Dto;
using Cogs.Model;
using Cogs.Publishers;
using Cogs.Validation;
using Microsoft.Extensions.CommandLineUtils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Cogs.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.WriteLine(cogsLogo);

            var app = new CommandLineApplication
            {
                Name = "Cogs"
            };
            app.HelpOption("-?|-h|--help");


            app.Command("publish-xsd", (command) =>
            {

                command.Description = "Publish an XML schema from a COGS data model";
                command.HelpOption("-?|-h|--help");

                var locationArgument = command.Argument("[cogsLocation]", "Directory where the COGS datamodel is located.");
                var targetArgument = command.Argument("[targetLocation]", "Directory where the xsd schema is generated.");

                var overwriteOption = command.Option("-o|--overwrite",
                                           "If the target directory exists, delete and overwrite the location",
                                           CommandOptionType.NoValue);

                var namespaceUri = command.Option("-n|--namespace",
                                           "URI of the target XML namespace",
                                           CommandOptionType.SingleValue);

                var namespaceUriPrefix = command.Option("-p|--namespacePrefix",
                                           "Namespace prefix to use for the target XML namespace",
                                           CommandOptionType.SingleValue);

                command.OnExecute(() =>
                {
                    var location = locationArgument.Value ?? Environment.CurrentDirectory;
                    var target = targetArgument.Value ?? Path.Combine(Directory.GetCurrentDirectory(), "out");
                    bool overwrite = overwriteOption.HasValue();
                    var targetNamespace = namespaceUri.Value() ?? "cogs:default";
                    var prefix = namespaceUri.Value() ?? "cogs";

                    // read cogs directory and validate the contents
                    var directoryReader = new CogsDirectoryReader();
                    var cogsDtoModel = directoryReader.Load(location);
                    HandleErrors(directoryReader.Errors);
                    HandleErrors(DtoValidation.Validate(cogsDtoModel));

                    var modelBuilder = new CogsModelBuilder();
                    var cogsModel = modelBuilder.Build(cogsDtoModel);
                    HandleErrors(modelBuilder.Errors);

                    XmlSchemaPublisher publisher = new XmlSchemaPublisher();
                    publisher.CogsLocation = location;
                    publisher.TargetDirectory = target;
                    publisher.Overwrite = overwrite;
                    publisher.TargetNamespace = targetNamespace;
                    publisher.TargetNamespacePrefix = prefix;

                    publisher.Publish(cogsModel);
                    HandleErrors(publisher.Errors);


                    return 0;
                });

            });


            app.Command("publish-uml", (command) =>
            {

                command.Description = "Publish an UML schema from a COGS data model";
                command.HelpOption("-?|-h|--help");

                var locationArgument = command.Argument("[cogsLocation]", "Directory where the COGS datamodel is located.");
                var targetArgument = command.Argument("[targetLocation]", "Directory where the UML schema is generated.");<commit_msg>closes #30 validation command line argument for cogs disk datamodel testing<commit_after>﻿// Copyright (c) 2017 Colectica. All rights reserved
// See the LICENSE file in the project root for more information.
using Cogs.Common;
using Cogs.Dto;
using Cogs.Model;
using Cogs.Publishers;
using Cogs.Validation;
using Microsoft.Extensions.CommandLineUtils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Cogs.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.WriteLine(cogsLogo);

            var app = new CommandLineApplication
            {
                Name = "Cogs"
            };
            app.HelpOption("-?|-h|--help");


            app.Command("validate", (command) =>
            {

                command.Description = "Validate a on disk COGS data model directory";
                command.HelpOption("-?|-h|--help");

                var locationArgument = command.Argument("[cogsLocation]", "Directory where the COGS datamodel is located.");                                

                command.OnExecute(() =>
                {
                    var location = locationArgument.Value ?? Environment.CurrentDirectory;

                    // read cogs directory and validate the contents
                    var directoryReader = new CogsDirectoryReader();
                    HandleErrors(directoryReader.Errors);
                    var cogsDtoModel = directoryReader.Load(location);
                    HandleErrors(DtoValidation.Validate(cogsDtoModel));

                    // this could find gaps in the validation, but idealy return nothing
                    var modelBuilder = new CogsModelBuilder();
                    var cogsModel = modelBuilder.Build(cogsDtoModel);
                    HandleErrors(modelBuilder.Errors);

                    return 0;
                });

            });

            app.Command("publish-xsd", (command) =>
            {

                command.Description = "Publish an XML schema from a COGS data model";
                command.HelpOption("-?|-h|--help");

                var locationArgument = command.Argument("[cogsLocation]", "Directory where the COGS datamodel is located.");
                var targetArgument = command.Argument("[targetLocation]", "Directory where the xsd schema is generated.");

                var overwriteOption = command.Option("-o|--overwrite",
                                           "If the target directory exists, delete and overwrite the location",
                                           CommandOptionType.NoValue);

                var namespaceUri = command.Option("-n|--namespace",
                                           "URI of the target XML namespace",
                                           CommandOptionType.SingleValue);

                var namespaceUriPrefix = command.Option("-p|--namespacePrefix",
                                           "Namespace prefix to use for the target XML namespace",
                                           CommandOptionType.SingleValue);

                command.OnExecute(() =>
                {
                    var location = locationArgument.Value ?? Environment.CurrentDirectory;
                    var target = targetArgument.Value ?? Path.Combine(Directory.GetCurrentDirectory(), "out");
                    bool overwrite = overwriteOption.HasValue();
                    var targetNamespace = namespaceUri.Value() ?? "cogs:default";
                    var prefix = namespaceUri.Value() ?? "cogs";

                    // read cogs directory and validate the contents
                    var directoryReader = new CogsDirectoryReader();
                    HandleErrors(directoryReader.Errors);
                    var cogsDtoModel = directoryReader.Load(location);
                    HandleErrors(DtoValidation.Validate(cogsDtoModel));

                    var modelBuilder = new CogsModelBuilder();
                    var cogsModel = modelBuilder.Build(cogsDtoModel);
                    HandleErrors(modelBuilder.Errors);

                    XmlSchemaPublisher publisher = new XmlSchemaPublisher();
                    publisher.CogsLocation = location;
                    publisher.TargetDirectory = target;
                    publisher.Overwrite = overwrite;
                    publisher.TargetNamespace = targetNamespace;
                    publisher.TargetNamespacePrefix = prefix;

                    publisher.Publish(cogsModel);
                    HandleErrors(publisher.Errors);


                    return 0;
                });

            });


            app.Command("publish-uml", (command) =>
            {

                command.Description = "Publish an UML schema from a COGS data model";
                command.HelpOption("-?|-h|--help");

                var locationArgument = command.Argument("[cogsLocation]", "Directory where the COGS datamodel is located.");
                var targetArgument = command.Argument("[targetLocation]", "Directory where the UML schema is generated.");
{'fraction_non_alphanumeric': 0.08760992986752755, 'fraction_numerical': 0.001447178002894356, 'mean_word_length': 1.6315172817809023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4190625', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1858, 'n_words': 515}