static int Main(string[] args) { Initialize(); MainArgs arguments; try { arguments = new MainArgs(args); } catch (DocoptExitException ex) { WriteLine(ex.Message); return(0); } catch (DocoptInputErrorException ex) { WriteErrorLine(ex.Message); return(1); } var parser = CreateParser(arguments); var links = parser.Parse().GetLinks(includeEmpty: arguments.IncludeEmptyLinks, includeHashLink: arguments.IncludeHashLinks, includeJavaScriptLink: arguments.IncludeJavaScriptLinks); var linksText = GetLinksText(links); if (!string.IsNullOrWhiteSpace(arguments.Output)) { File.WriteAllText(arguments.Output, linksText); } else { WriteLine($"Links:\n{linksText}"); } return(0); }
private static Parser CreateParser(MainArgs arguments) { if (arguments.InputRedirected && Console.IsInputRedirected) { using (var reader = new StreamReader(Console.OpenStandardInput(), Console.InputEncoding)) { var stdin = reader.ReadToEnd(); return(new Parser(stdin)); } } if (!arguments.IsUrl) { return(new Parser(arguments.UrlOrContent)); } var url = new Uri(arguments.UrlOrContent); if (!arguments.UseBrowser) { return(new Parser(url)); } return(new Parser(new Scraper(url).FetchHtml(!arguments.Verbose))); }