#pragma warning disable CS3002 // Return type is not CLS-compliant
        internal static OptionSet GetOptionSetFor(DataSetCheckerOptions options)
#pragma warning restore CS3002 // Return type is not CLS-compliant
        {
            return(new OptionSet
            {
                { "h|help", "show this message and exit", (bool showHelp) => options.ShowHelp = showHelp },
                { "w", "suppress warning messages", noWarn => options.NoWarnings = noWarn != null },
                {
                    "<>",
                    arg =>
                    {
                        if (options.ConnectionString == null)
                        {
                            // First argument is connection string
                            options.ConnectionString = arg;
                        }
                        else
                        {
                            // Subsequent arguments are XSDs
                            options.DataSetFilePaths.Add(arg);
                        }
                    }
                },
            });
        }
        /// <summary>
        /// Entry-point to check a named XSD against a given collection.
        /// </summary>
        /// <param name="args">Command-line arguments.  First is a connection
        /// string.  All subsequent arguments are paths to XSD files to
        /// check.</param>
        /// <returns>0 if the XSD passes all checks.  1 Otherwise.</returns>
        public static int Main(string[] args)
        {
            DataSetCheckerOptions options   = new DataSetCheckerOptions();
            OptionSet             optionSet = GetOptionSetFor(options);

            try
            {
                optionSet.Parse(args);
            }
            catch (OptionException ex)
            {
                Console.Error.WriteLine("Error parsing options: {0}", ex);
                return(1);
            }

            if (options.ShowHelp)
            {
                optionSet.WriteOptionDescriptions(Console.Out);
                return(0);
            }

            if (options.DataSetFilePaths.Count == 0)
            {
                Console.Error.WriteLine("Error: Missing required arguments.");
                optionSet.WriteOptionDescriptions(Console.Error);
                return(1);
            }

            int exitCode = 0;

            using (DataSetChecker checker = new DataSetChecker(options.ConnectionString))
            {
                checker.DataSetCheckerEventHandler += (object sender, DataSetCheckerEventArgs eventArgs) =>
                {
                    if (eventArgs.Severity == XmlSeverityType.Error || !options.NoWarnings)
                    {
                        Console.Error.WriteLine(eventArgs);
                    }
                };

                foreach (string xsdPath in options.DataSetFilePaths)
                {
                    try
                    {
                        // TODO: Set exit code based on non-fatal validation errors
                        checker.Check(xsdPath);
                    }
                    catch (XmlException ex)
                    {
                        Console.Error.WriteLine("Error checking {0}: {1}", xsdPath, ex);
                        exitCode = 1;
                    }
                }
            }

            return(exitCode);
        }