From 9d89965b0661d1968151d9b646148b6a71209705 Mon Sep 17 00:00:00 2001 From: Jan Sucan Date: Sun, 14 Sep 2025 17:10:23 +0200 Subject: 23_a_2: Add solution --- ch23/23_a_1/PodMainCLI.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ch23/23_a_1/PodMainCLI.hs (limited to 'ch23/23_a_1/PodMainCLI.hs') diff --git a/ch23/23_a_1/PodMainCLI.hs b/ch23/23_a_1/PodMainCLI.hs new file mode 100644 index 0000000..ed26430 --- /dev/null +++ b/ch23/23_a_1/PodMainCLI.hs @@ -0,0 +1,31 @@ +{-- From examples/examples/ch22/PodMain.hs and modified --} +module Main where + +import PodMain +import PodDownload +import PodDB +import PodTypes +import System.Environment +import Database.HDBC +import Network.Socket(withSocketsDo) + +main = withSocketsDo $ handleSqlError $ + do args <- getArgs + dbh <- connect "pod.db" + case args of + ["add", url] -> addUrl dbh url + ["update"] -> update dbh putStrLn + ["download"] -> download dbh putStrLn + ["fetch"] -> do update dbh putStrLn + download dbh putStrLn + _ -> syntaxError + disconnect dbh + +syntaxError = putStrLn + "Usage: pod command [args]\n\ + \\n\ + \pod add url Adds a new podcast with the given URL\n\ + \pod download Downloads all pending episodes\n\ + \pod fetch Updates, then downloads\n\ + \pod update Downloads podcast feeds, looks for new episodes\n" +{-- End of code from examples --} -- cgit v1.2.3