louse.hs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. -- louse - distributed bugtracker
  2. -- Copyright (C) 2015 Peter Harpending
  3. --
  4. -- This program is free software: you can redistribute it and/or modify
  5. -- it under the terms of the GNU General Public License as published by
  6. -- the Free Software Foundation, either version 3 of the License, or (at
  7. -- your option) any later version.
  8. --
  9. -- This program is distributed in the hope that it will be useful, but
  10. -- WITHOUT ANY WARRANTY; without even the implied warranty of
  11. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. -- General Public License for more details.
  13. --
  14. -- You should have received a copy of the GNU General Public License
  15. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. -- |
  17. -- Module : Main
  18. -- Description : Runs louse program
  19. -- Copyright : Copyright (C) 2015 Peter Harpending
  20. -- License : GPL-3
  21. -- Maintainer : Peter Harpending <peter@harpending.org>
  22. -- Stability : experimental
  23. -- Portability : UNIX/GHC
  24. --
  25. module Main where
  26. import Control.Applicative
  27. import Data.Louse
  28. import Data.Louse.Trivia
  29. import Data.Monoid
  30. import Data.Version hiding (Version)
  31. import Options.Applicative
  32. import Paths_louse
  33. import System.IO
  34. main :: IO ()
  35. main = execParser argsParserInfo >>= runArgs
  36. altConcat :: Alternative f => [f a] -> f a
  37. altConcat [] = empty
  38. altConcat (x:xs) = x <|> altConcat xs
  39. infoHelp :: Parser a -> InfoMod a -> ParserInfo a
  40. infoHelp a = info (helper <*> a)
  41. data Args = DBug BugAction
  42. | Copyright
  43. | InitInteractive
  44. | License
  45. | Readme
  46. | Schema SchemaAction
  47. | Tutorial
  48. | Version
  49. deriving Show
  50. data BugAction = AddBug
  51. deriving Show
  52. data SchemaAction = ListSchemata
  53. | Path
  54. | ShowSchema String
  55. deriving Show
  56. runArgs :: Args -> IO ()
  57. runArgs (DBug AddBug) = addBugToCurrentProject
  58. runArgs Copyright = printOut louseCopyright
  59. runArgs InitInteractive = initialize
  60. runArgs License = printOut louseLicense
  61. runArgs Readme = printOut louseReadme
  62. runArgs (Schema ListSchemata) = listSchemata
  63. runArgs (Schema Path) = showSchemaDir
  64. runArgs (Schema (ShowSchema s)) = showSchema s
  65. runArgs Tutorial = printOut louseTutorial
  66. runArgs Version = printVersion
  67. runArgs x = print x
  68. argsParserInfo :: ParserInfo Args
  69. argsParserInfo = infoHelp argsParser argsHelp
  70. where
  71. argsHelp :: InfoMod Args
  72. argsHelp = mconcat
  73. [ fullDesc
  74. , header ("louse v." <> showVersion version)
  75. , progDesc "A distributed bug tracker."
  76. , footer
  77. "For information on a specific command, run `louse COMMAND --help`, where COMMAND is one of the commands listed above."
  78. ]
  79. argsParser :: Parser Args
  80. argsParser = altConcat
  81. [ copyrightParser
  82. , licenseParser
  83. , readmeParser
  84. , tutorialParser
  85. , versionParser
  86. , hsubparser (command "bug" bugInfo)
  87. , hsubparser (command "init" initInfo)
  88. , hsubparser (command "schema" schemataInfo)
  89. , hsubparser (command "schemata" schemataInfo)
  90. ]
  91. copyrightParser :: Parser Args
  92. copyrightParser = flag' Copyright (help ("Print the copyright.") <>
  93. long "copyright")
  94. versionParser :: Parser Args
  95. versionParser = flag' Version (help ("Print the version (" <> showVersion version <> ").") <>
  96. long "version")
  97. licenseParser :: Parser Args
  98. licenseParser = flag' License (help "Print the license (GPL version 3)." <>
  99. long "license")
  100. tutorialParser :: Parser Args
  101. tutorialParser = flag' Tutorial (help "Print the tutorial." <>
  102. long "tutorial")
  103. readmeParser :: Parser Args
  104. readmeParser = flag' Readme (help "Print the README." <>
  105. long "readme")
  106. initInfo :: ParserInfo Args
  107. initInfo = infoHelp theOptions theHelp
  108. where
  109. theOptions = pure InitInteractive
  110. theHelp = fullDesc <> progDesc "Initialize louse using $EDITOR."
  111. schemataInfo :: ParserInfo Args
  112. schemataInfo = infoHelp schemataOptions schemataHelp
  113. where
  114. schemataHelp = fullDesc <> progDesc "Do stuff with schemata."
  115. schemataOptions :: Parser Args
  116. schemataOptions = altConcat
  117. [ subparser (command "dir" pathSchemaInfo)
  118. , subparser (command "list" listSchemataInfo)
  119. , subparser (command "path" pathSchemaInfo)
  120. , subparser (command "show" showSchemaInfo)
  121. ]
  122. showSchemaInfo :: ParserInfo Args
  123. showSchemaInfo = infoHelp theOptions theHelp
  124. where
  125. theHelp = fullDesc <> progDesc "Show a specific schema."
  126. theOptions = fmap Schema $ ShowSchema <$> strArgument (help "The schema to show")
  127. listSchemataInfo :: ParserInfo Args
  128. listSchemataInfo = infoHelp theOptions theHelp
  129. where
  130. theHelp = fullDesc <> progDesc "List the available schemata"
  131. theOptions = pure $ Schema ListSchemata
  132. pathSchemaInfo :: ParserInfo Args
  133. pathSchemaInfo = infoHelp theOptions theHelp
  134. where
  135. theHelp = fullDesc <> progDesc "Show the directory in which the schemata are stored"
  136. theOptions = pure $ Schema Path
  137. bugInfo :: ParserInfo Args
  138. bugInfo = infoHelp theOptions theHelp
  139. where
  140. theHelp = fullDesc <> progDesc "Do stuff with bugs."
  141. theOptions = altConcat
  142. [ subparser (command "add" addBugInfo)
  143. ]
  144. addBugInfo = infoHelp abopts abhelp
  145. abhelp = fullDesc <> progDesc "Add a bug"
  146. abopts = pure $ DBug AddBug