Main.hs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 Control.Applicative
  33. import qualified Data.ByteString as B
  34. import Data.Char
  35. import Data.Data
  36. import qualified Data.Map.Lazy as Map
  37. import Data.Monoid
  38. import qualified Data.Text as T
  39. import Data.Time
  40. import Data.Typeable
  41. import Data.Version
  42. import Paths_tn (version)
  43. import Safe
  44. import System.Directory
  45. import System.Environment
  46. import System.Exit
  47. import System.IO
  48. import System.IO.Error
  49. import System.Process
  50. import Tn.Meat
  51. import Tn.Potatoes
  52. import Tn.Static
  53. -- |=== Let's get 'main' out of the way
  54. --
  55. -- I don't like putting 'main' at the end, so I'm just going to put it
  56. -- here. We'll define each of the function later
  57. --
  58. main :: IO ()
  59. main = do
  60. -- Get the arguments
  61. args <- getArgs
  62. -- @--help@ gets first priority
  63. if or ["--help" `elem` args, "-h" `elem` args]
  64. then help
  65. else if "--version" `elem` args
  66. then putStrLn tnVersion
  67. else runTn
  68. -- |Main was getting a bit long, so I took the latter half of it and
  69. -- put it into another function.
  70. runTn :: IO ()
  71. runTn = do
  72. args <- getArgs
  73. let fstarg = headMay args
  74. rstof = tailMay args
  75. case fstarg of
  76. Nothing -> editToday =<< getTheTn
  77. Just cmd ->
  78. case cmd of
  79. "edit" ->
  80. case rstof of
  81. Just (s:_) ->
  82. case readMay s of
  83. Nothing -> help
  84. Just d -> getTheTn >>= \theTn -> editEntry theTn d
  85. _ -> help
  86. "initialize" -> initialize
  87. _ -> help