示例#1
0
        public static void Start(string[] arguments)
        {
            var origin = arguments;

            arguments = CommandLineUtil.SplitCombinedOptions(arguments);
            arguments = CommandLineUtil.InsertWeirdArguments <Options>(arguments, true, "--url");
            var option = CommandLineParser.Parse <Options>(arguments);

            //
            //  Multi Commands
            //
            if (option.Net)
            {
                NetConsole.Start(origin.Skip(1).ToArray());
            }
            //
            //  Single Commands
            //
            else if (option.Help)
            {
                PrintHelp();
            }
            else if (option.Version)
            {
                PrintVersion();
            }
            else if (option.DialogMode)
            {
                Dialog.StartDialog();
            }
            else if (option.ListExtractor)
            {
                foreach (var extractor in ExtractorManager.Extractors)
                {
                    System.Console.WriteLine($"[{extractor.GetType().Name}]");
                    System.Console.WriteLine($"[HostName] {extractor.HostName}");
                    System.Console.WriteLine($"[Checker] {extractor.ValidUrl}");
                    System.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() != "")
                    {
                        System.Console.WriteLine($"[Options]");
                        System.Console.Write(builder.ToString());
                    }
                    System.Console.WriteLine($"-------------------------------------------------------------");
                }
            }
            else if (option.Url != null)
            {
                if (!(option.Url[0].StartsWith("https://") || option.Url[0].StartsWith("http://")))
                {
                    System.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)
            {
                System.Console.WriteLine(option.ErrorMessage);
                if (option.HelpMessage != null)
                {
                    System.Console.WriteLine(option.HelpMessage);
                }
                return;
            }
            else
            {
                System.Console.WriteLine("Nothing to work on.");
                System.Console.WriteLine("Enter './Koromo_Copy.Console --help' to get more information");
            }

            return;
        }