private static async Task Main(string[] args)
        {
            // setup the config with defaults
            ScraperConfig config = new ScraperConfig()
            {
                PageSize            = _defaultPageSize,
                RunOnlyOnePage      = _defaultRunOnlyOnePage,
                SaveCandidatePacks  = _defaultSaveCandidatePacks,
                IncludePreviewPacks = _defaultIncludePreviewPacks
            };

            if (!TryParseArgs(args, config) || string.IsNullOrEmpty(config.BasePath))
            {
                // base path is the only required arg.
                ShowUsageMessage();
                return;
            }

            PackSourceChecker packSourceChecker;

            // if or when we add other sources to scrape, input args can control which execute(s).
            if (true)
            {
                if (!NugetPackScraper.TryCreateDefaultNugetPackScraper(config, out packSourceChecker))
                {
                    Console.WriteLine("Unable to create the NugetPackScraper.");
                    return;
                }
            }
            else
            {
                throw new NotImplementedException("no checker for the input options");
            }

            PackSourceCheckResult checkResults = await packSourceChecker.CheckPackagesAsync().ConfigureAwait(false);

            PackCheckResultReportWriter.TryWriteResults(config.BasePath, checkResults);
        }
        private static bool TryParseArgs(string[] args, ScraperConfig config)
        {
            int index = 0;

            while (index < args.Length)
            {
                if (string.Equals(args[index], _basePathFlag, StringComparison.Ordinal))
                {
                    if (TryGetFlagValue(args, index, out string basePath))
                    {
                        config.BasePath = basePath;
                        index          += 2;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (string.Equals(args[index], _pageSizeFlag, StringComparison.Ordinal))
                {
                    if (TryGetFlagValue(args, index, out string pageSizeString) && int.TryParse(pageSizeString, out int pageSize))
                    {
                        config.PageSize = pageSize;
                        index          += 2;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (string.Equals(args[index], _previousOutputBasePathFlag, StringComparison.Ordinal))
                {
                    if (TryGetFlagValue(args, index, out string previousOutputBasePath))
                    {
                        config.PreviousRunBasePath = previousOutputBasePath;
                        index += 2;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (string.Equals(args[index], _runOnlyOnePageFlag, StringComparison.Ordinal))
                {
                    config.RunOnlyOnePage = true;
                    ++index;
                }
                else if (string.Equals(args[index], _saveDownloadedPacksFlag, StringComparison.Ordinal))
                {
                    config.SaveCandidatePacks = true;
                    ++index;
                }
                else if (string.Equals(args[index], _includePreviewPacksFlag, StringComparison.Ordinal))
                {
                    config.IncludePreviewPacks = true;
                    ++index;
                }
                else if (string.Equals(args[index], _noTemplateJsonFilterFlag, StringComparison.Ordinal))
                {
                    config.DontFilterOnTemplateJson = true;
                    ++index;
                }
                else if (string.Equals(args[index], _verbose, StringComparison.Ordinal))
                {
                    Verbose.IsEnabled = true;
                    ++index;
                }
                else if (string.Equals(args[index], _providers, StringComparison.Ordinal))
                {
                    if (TryGetFlagValue(args, index, out string providersList))
                    {
                        config.Providers.AddRange(providersList.Split('|', StringSplitOptions.TrimEntries));
                        foreach (string provider in config.Providers)
                        {
                            if (!NugetPackScraper.SupportedProvidersList.Contains(provider, StringComparer.OrdinalIgnoreCase))
                            {
                                Console.WriteLine($"Provider {provider} is not supported. Supported providers: {string.Join(",", NugetPackScraper.SupportedProvidersList)}.");
                                return(false);
                            }
                        }
                        index += 2;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        private static bool TryParseArgs(string[] args, ScraperConfig config)
        {
            int index = 0;

            while (index < args.Length)
            {
                if (string.Equals(args[index], _basePathFlag, StringComparison.Ordinal))
                {
                    if (TryGetFlagValue(args, index, out string basePath))
                    {
                        config.BasePath = basePath;
                        index          += 2;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (string.Equals(args[index], _pageSizeFlag, StringComparison.Ordinal))
                {
                    if (TryGetFlagValue(args, index, out string pageSizeString) && int.TryParse(pageSizeString, out int pageSize))
                    {
                        config.PageSize = pageSize;
                        index          += 2;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (string.Equals(args[index], _previousOutputBasePathFlag, StringComparison.Ordinal))
                {
                    if (TryGetFlagValue(args, index, out string previousOutputBasePath))
                    {
                        config.PreviousRunBasePath = previousOutputBasePath;
                        index += 2;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (string.Equals(args[index], _runOnlyOnePageFlag, StringComparison.Ordinal))
                {
                    config.RunOnlyOnePage = true;
                    ++index;
                }
                else if (string.Equals(args[index], _saveDownloadedPacksFlag, StringComparison.Ordinal))
                {
                    config.SaveCandidatePacks = true;
                    ++index;
                }
                else if (string.Equals(args[index], _includePreviewPacksFlag, StringComparison.Ordinal))
                {
                    config.IncludePreviewPacks = true;
                    ++index;
                }
                else if (string.Equals(args[index], _noTemplateJsonFilterFlag, StringComparison.Ordinal))
                {
                    config.DontFilterOnTemplateJson = true;
                    ++index;
                }
                else if (string.Equals(args[index], _verbose, StringComparison.Ordinal))
                {
                    Verbose.IsEnabled = true;
                    ++index;
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }