Example #1
0
        public static void Start(string[] arguments)
        {
            arguments = CommandLineUtil.SplitCombinedOptions(arguments);
            arguments = CommandLineUtil.InsertWeirdArguments <Options>(arguments, true, "--url");
            var option = CommandLineParser.Parse <Options>(arguments);

            //
            //  Single Commands
            //
            if (option.Help)
            {
                PrintHelp();
            }
            else if (option.Version)
            {
                PrintVersion();
            }
            else if (option.RecoverSettings)
            {
                Settings.Instance.Recover();
                Settings.Instance.Save();
            }
            else if (option.BuildData)
            {
                ProcessBuildData();
            }
            else if (option.StartsWithClient)
            {
                ProcessStartsWithClient();
            }
            else if (option.ListExtractor)
            {
                foreach (var extractor in ExtractorManager.Extractors)
                {
                    Console.WriteLine($"[{extractor.GetType().Name}]");
                    Console.WriteLine($"[HostName] {extractor.HostName}");
                    Console.WriteLine($"[Checker] {extractor.ValidUrl}");
                    Console.WriteLine($"[Information] {extractor.ExtractorInfo}");
                    var builder = new StringBuilder();
                    CommandLineParser.GetFields(extractor.RecommendOption("").GetType()).ToList().ForEach(
                        x =>
                    {
                        var key = x.Key;
                        if (!key.StartsWith("--"))
                        {
                            return;
                        }
                        if (!string.IsNullOrEmpty(x.Value.Item2.ShortOption))
                        {
                            key = $"{x.Value.Item2.ShortOption}, " + key;
                        }
                        var help = "";
                        if (!string.IsNullOrEmpty(x.Value.Item2.Help))
                        {
                            help = $"[{x.Value.Item2.Help}]";
                        }
                        if (!string.IsNullOrEmpty(x.Value.Item2.Info))
                        {
                            builder.Append($"   {key}".PadRight(30) + $" {x.Value.Item2.Info} {help}\r\n");
                        }
                        else
                        {
                            builder.Append($"   {key}".PadRight(30) + $" {help}\r\n");
                        }
                    });
                    if (builder.ToString() != "")
                    {
                        Console.WriteLine($"[Options]");
                        Console.Write(builder.ToString());
                    }
                    Console.WriteLine($"-------------------------------------------------------------");
                }
            }
            else if (option.Url != null)
            {
                if (!(option.Url[0].StartsWith("https://") || option.Url[0].StartsWith("http://")))
                {
                    Console.WriteLine($"'{option.Url[0]}' is not correct url format or not supported scheme.");
                }

                var weird  = CommandLineUtil.GetWeirdArguments <Options>(arguments);
                var n_args = new List <string>();

                weird.ForEach(x => n_args.Add(arguments[x]));

                ProcessExtract(option.Url[0], n_args.ToArray(), option.PathFormat, option.ExtractInformation, option.ExtractLinks, option.PrintProcess, option.DisableDownloadProgress);
            }
            else if (option.Error)
            {
                Console.WriteLine(option.ErrorMessage);
                if (option.HelpMessage != null)
                {
                    Console.WriteLine(option.HelpMessage);
                }
                return;
            }
            else
            {
                Console.WriteLine("Nothing to work on.");
                Console.WriteLine("Enter './custom-copy-backend --help' to get more information");
            }

            return;
        }