X-Git-Url: http://gitweb.michael.orlitzky.com/?p=list-remote-forwards.git;a=blobdiff_plain;f=src%2FMain.hs;h=66d02a084449102dace81985744afdf25e4da8f6;hp=d1d1ea81fa43516bd44b01b294326451b9fbafaf;hb=ae4cdbc0662d67d3d325c8ab567e0d45a84413b3;hpb=e3ef76e60ddd54e5fad787c5883533d2410b3e2a diff --git a/src/Main.hs b/src/Main.hs index d1d1ea8..66d02a0 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -12,10 +12,12 @@ import Database.HDBC.Sqlite3 ( connectSqlite3 ) import System.Console.CmdArgs ( def ) import System.Directory ( doesFileExist ) import System.IO ( hPutStrLn, stderr ) + import CommandLine ( get_args ) import Configuration ( Configuration(..), merge_optional ) import qualified OptionalConfiguration as OC ( from_rc ) import Report ( report ) +import String ( trim ) -- | Construct a connection string (postgres-only, for now) from a @@ -23,7 +25,7 @@ import Report ( report ) -- Postgres, and so we want to avoid appending e.g. \"host=\" to the -- connection string if @(host cfg)@ is 'Nothing'. -- --- Examples: +-- ==== __Examples__ -- -- >>> let default_cfg = def :: Configuration -- >>> let cfg = default_cfg { host = Just "localhost" } @@ -37,11 +39,6 @@ connection_string :: Configuration -> String connection_string cfg = trim $ join " " [host_part, port_part, user_part, pw_part, db_part] where - -- | Strip leading/trailing whitespace, and collapse multiple - -- consecutive spaces into one. - trim :: String -> String - trim = unwords . words - host_part = let h = fmap ("host=" ++) (host cfg) in fromMaybe "" h port_part = let p = fmap (("port=" ++) . show) (port cfg) in fromMaybe "" p user_part = let u = fmap ("user=" ++) (username cfg) in fromMaybe "" u @@ -54,7 +51,7 @@ main = do rc_cfg <- OC.from_rc cmd_cfg <- get_args - -- Merge the config file options with the command-line ones, + -- Merge the config file options with the command-line ones, -- prefering the command-line ones. let opt_config = rc_cfg <> cmd_cfg @@ -77,9 +74,9 @@ main = do else connectPostgreSQL (connection_string cfg) >>= report cfg -- The DB connection is implicitly closed when it gets garbage collected. - putStrLn r + putStr r where show_sql_error :: SqlError -> IO () show_sql_error se = hPutStrLn stderr $ - "SQL Error (" ++ (show $ seNativeError se) ++ "): " ++ (seErrorMsg se) + "SQL Error (" ++ show (seNativeError se) ++ "): " ++ (seErrorMsg se)