diff options
| author | Jan Sucan <jan@jansucan.com> | 2025-09-14 17:10:23 +0200 |
|---|---|---|
| committer | Jan Sucan <jan@jansucan.com> | 2025-09-14 21:18:59 +0200 |
| commit | 9d89965b0661d1968151d9b646148b6a71209705 (patch) | |
| tree | 6da0620222dabbf8dd9c038af305a174d4c68868 /ch23/23_a_1/PodMainCLI.hs | |
| parent | ad4cf7db4cd61d01f1e2191d1d69edd5916d6e88 (diff) | |
23_a_2: Add solution
Diffstat (limited to 'ch23/23_a_1/PodMainCLI.hs')
| -rw-r--r-- | ch23/23_a_1/PodMainCLI.hs | 31 |
1 files changed, 31 insertions, 0 deletions
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 --}
|
