Changes ArgParser to read info from cabal file.

pull/1/head
Abhinav Sarkar 2016-04-20 16:40:01 +05:30
parent c5e7fd0683
commit 835e30ca97
3 changed files with 52 additions and 13 deletions

View File

@ -0,0 +1,29 @@
module Distribution.CurrentPackageDescription
( currentPackageDescription
, getField
) where
import Distribution.PackageDescription
import Distribution.PackageDescription.Parse
import Distribution.Verbosity
import Data.List (isSuffixOf)
import Language.Haskell.TH (stringE, runIO, Q, Exp)
import System.Directory (getCurrentDirectory, getDirectoryContents)
getField :: (PackageDescription -> String) -> Q Exp
getField f = runIO currentPackageDescription >>= stringE . f
currentPackageDescription :: IO PackageDescription
currentPackageDescription = fmap packageDescription $ do
dir <- getCurrentDirectory
cs <- cabalFiles dir
case cs of
(c:_) -> readPackageDescription silent c
[] -> error $ "Couldn't find a cabal file in the current working directory (" ++ dir ++ ")"
cabalFiles :: FilePath -> IO [FilePath]
cabalFiles dir = do
files <- getDirectoryContents dir
return $ filter (".cabal" `isSuffixOf`) files

View File

@ -1,15 +1,17 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
module Ringo.ArgParser (ProgArgs(..), parseArgs) where
import qualified Data.Text as Text
import qualified Distribution.Package as P
import qualified Distribution.PackageDescription as P
import qualified Distribution.CurrentPackageDescription as P
import qualified Distribution.Text as DText
import Data.List (intercalate)
import Data.Version (showVersion)
import Options.Applicative
import Paths_ringo (version)
import Ringo.Types
data ProgArgs = ProgArgs
@ -98,15 +100,20 @@ progArgsParser =
<> action "directory"
<> help "Output directory")
progName :: String
progName = $(P.getField (DText.display . P.pkgName . P.package))
versionParser :: Parser (a -> a)
versionParser = infoOption ("ringo " ++ showVersion version)
versionParser = infoOption (progName ++ " " ++ version)
(long "version"
<> help "Print version information")
where
version = $(P.getField (DText.display . P.pkgVersion . P.package))
parseArgs :: IO ProgArgs
parseArgs = execParser $
info (helper <*> versionParser <*> progArgsParser)
(fullDesc
<> progDesc "Transforms OLTP database schemas to OLAP database star schemas"
<> header "ringo - OLTP to OLAP schema transformer"
<> footer "Source: http://github.com/quintype/ringo")
<> progDesc $(P.getField P.description)
<> header (progName ++ " - " ++ $(P.getField P.synopsis))
<> footer ("© " ++ $(P.getField P.copyright) ++ ". " ++ $(P.getField P.homepage)))

View File

@ -1,13 +1,13 @@
name: ringo
version: 0.1.0.0
synopsis: Tool to transform OLTP schemas to OLAP star schemas automatically
description: Please see README.md
homepage: http://github.com/quintype/ringo#readme
synopsis: OLTP to OLAP schema transformer
description: Tool to transform OLTP schemas to OLAP star schemas automatically
homepage: http://github.com/quintype/ringo
license: MIT
license-file: LICENSE
author: Abhinav Sarkar
maintainer: abhinav@abhinavsarkar.net
copyright: 2015 Quintype Inc, Nilenso Software LLP
copyright: 2015-2016 Quintype Inc, Nilenso Software LLP
category: SQL
build-type: Simple
-- extra-source-files:
@ -41,7 +41,8 @@ library
executable ringo
hs-source-dirs: app
other-modules: Ringo.ArgParser,
Ringo.InputParser
Ringo.InputParser,
Distribution.CurrentPackageDescription
main-is: Main.hs
build-depends: base >=4.7 && <5,
text >=1.2 && <1.3,
@ -53,6 +54,8 @@ executable ringo
directory >=1.2 && <1.3,
filepath >=1.3 && <1.5,
aeson >=0.8 && <0.12,
Cabal >=1.18 && <1.23,
template-haskell >=2.9 && <2.11,
ringo
ghc-options: -Wall -Werror -fwarn-incomplete-uni-patterns -fno-warn-unused-do-bind
-fno-warn-orphans -funbox-strict-fields -O2