Main.hs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. -- Tn - a simple journal program
  2. -- Copyright (C) 2015 Peter Harpending
  3. --
  4. -- === License disclaimer
  5. --
  6. -- This program is free software: you can redistribute it and/or modify
  7. -- it under the terms of the GNU General Public License as published by
  8. -- the Free Software Foundation, either version 3 of the License, or (at
  9. -- your option) any later version.
  10. --
  11. -- This program is distributed in the hope that it will be useful, but
  12. -- WITHOUT ANY WARRANTY; without even the implied warranty of
  13. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. -- General Public License for more details.
  15. --
  16. -- You should have received a copy of the GNU General Public License
  17. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. -- |
  19. -- Module : Main
  20. -- Description : Runs tn
  21. -- Copyright : Copyright (C) 2015 Peter Harpending
  22. -- License : GPL-3
  23. -- Maintainer : Peter Harpending <peter@harpending.org>
  24. -- Stability : experimental
  25. -- Portability : UNIX/GHC
  26. --
  27. -- This runs @tn@. This module isn't very interesting, it just
  28. -- processes command line arguments, and then sends the relevant
  29. -- information to "Tn.Meat".
  30. module Main where
  31. -- Here are some imports:
  32. import Safe
  33. import System.Environment
  34. import Tn.Meat
  35. import Tn.Potatoes
  36. import Tn.Static
  37. -- |=== Let's get 'main' out of the way
  38. --
  39. -- I don't like putting 'main' at the end, so I'm just going to put it
  40. -- here. We'll define each of the function later
  41. --
  42. main :: IO ()
  43. main = do
  44. -- Get the arguments
  45. args <- getArgs
  46. -- @--help@ gets first priority
  47. if or ["--help" `elem` args, "-h" `elem` args]
  48. then help
  49. else if "--version" `elem` args
  50. then putStrLn tnVersion
  51. else runTn
  52. -- |Main was getting a bit long, so I took the latter half of it and
  53. -- put it into another function.
  54. runTn :: IO ()
  55. runTn = do
  56. args <- getArgs
  57. let fstarg = headMay args
  58. rstof = tailMay args
  59. case fstarg of
  60. Nothing -> editToday =<< getTheTn
  61. Just cmd ->
  62. case cmd of
  63. "edit" ->
  64. case rstof of
  65. Just (s:_) ->
  66. case readMay s of
  67. Nothing -> help
  68. Just d -> getTheTn >>= \theTn -> editEntry theTn d
  69. _ -> help
  70. "initialize" -> initialize
  71. _ -> help