diff --git a/ghc-geode.cabal b/ghc-geode.cabal index 40f21705208347f5296f22862759d98b94f849f5..08ed85cc2b3274079e4244c29911fe2464bc313e 100644 --- a/ghc-geode.cabal +++ b/ghc-geode.cabal @@ -1,5 +1,5 @@ cabal-version: 2.4 -name: ghc-geode +name: geode version: 0.1.0.0 synopsis: Data structures and tooling used in project GEODE @@ -34,6 +34,7 @@ library , bytestring >= 0.11.3 && <0.12 , containers >= 0.6.5.1 && <0.7 , cassava >= 0.5.3 && <0.6 + , optparse-applicative >= 0.13.2 && < 0.18 , text >= 1.2.5 && <1.3 , vector >= 0.12.3.1 && <0.13 hs-source-dirs: lib diff --git a/guix.scm b/guix.scm index 7ff7bd19d027993fc4aed76a7015a4102796fb6f..1986f26f6f2179e0a7ba4ec60f2ef947c7f02548 100644 --- a/guix.scm +++ b/guix.scm @@ -1,4 +1,5 @@ -(use-modules ((gnu packages haskell-xyz) #:select (ghc-cassava)) +(use-modules ((gnu packages haskell-xyz) #:select (ghc-cassava + ghc-optparse-applicative)) ((guix build-system haskell) #:select (haskell-build-system)) ((guix git-download) #:select (git-predicate)) ((guix gexp) #:select (local-file)) @@ -15,7 +16,7 @@ #:recursive? #t #:select? (git-predicate %source-dir))) (build-system haskell-build-system) - (inputs (list ghc-cassava)) + (inputs (list ghc-cassava ghc-optparse-applicative)) (home-page "https://gitlab.liris.cnrs.fr/geode/ghc-geode") (synopsis "Data structures and tooling used in project GEODE") (description diff --git a/lib/Options/GEODE.hs b/lib/Options/GEODE.hs new file mode 100644 index 0000000000000000000000000000000000000000..210e87b376f9f76973680d35be071573d3f7a297 --- /dev/null +++ b/lib/Options/GEODE.hs @@ -0,0 +1,40 @@ +module Options.GEODE + ( Output(..) + , output ) where + +import Control.Applicative (optional) +import Data.Maybe (catMaybes) +import Options.Applicative + ( Parser, flag, help, long, metavar, short + , strOption ) + +data OutputFlags = + OutputFlags + { metadata :: Maybe () + , textRoot :: Maybe FilePath + , xmlRoot :: Maybe FilePath } + +data Output = Metadata | TextRoot FilePath | XMLRoot FilePath + +outputFlags :: Parser OutputFlags +outputFlags = OutputFlags + <$> flag Nothing (Just ()) + ( long "metadata" + <> short 'm' + <> help "Print metadata for splitted files on stdout" ) + <*> (optional . strOption) + ( long "text-root" + <> short 't' + <> metavar "DIRECTORY" + <> help "Path where to create files containing the text version of the articles" ) + <*> (optional . strOption) + ( long "xml-root" + <> short 'x' + <> metavar "DIRECTORY" + <> help "Path where to create files containing the XML" ) + +output :: Parser [Output] +output = catMaybes . toList <$> outputFlags + where + toList (OutputFlags {metadata, textRoot, xmlRoot}) = + [ Metadata <$ metadata, TextRoot <$> textRoot, XMLRoot <$> xmlRoot ]