-
Notifications
You must be signed in to change notification settings - Fork 2
/
BrowserX.hs
34 lines (29 loc) · 931 Bytes
/
BrowserX.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import System.Process
import System.Environment
import System.Exit
import Control.Monad
import System.Console.GetOpt
import Data.Char
import BrowserX.Webkit
import BrowserX.Network
import BrowserX.Options
import BrowserX.Parser
-- | 'main' runs the main program
main :: IO ()
main = do
argv <- getArgs
(settings, params) <- parse argv
when (optShowHelp settings) $ putStrLn (usageInfo "Usage: BrowserX [flags] [METHOD] URL [ITEM [ITEM]]" options) >> exitSuccess
when (optShowVersion settings) $ putStrLn "BrowserX: version: 0.1" >> exitSuccess
putStrLn $ show settings
putStrLn $ show params
url <- case params of
[] -> return "http://google.com"
(x:xs) -> return x
when (optDebug settings) $ console settings url
unless (optDebug settings) $ browser settings url
console :: Options -> String -> IO ()
console settings url = do
html <- fetchURL settings url
out <- parseHTML html
putStrLn out