From 89b91aa6f5788a9266f733a7cce725180c54f308 Mon Sep 17 00:00:00 2001 From: Alice BRENON <alice.brenon@ens-lyon.fr> Date: Mon, 5 Jun 2023 17:24:35 +0200 Subject: [PATCH] Take output options from EDdAClinic --- ghc-geode.cabal | 3 ++- guix.scm | 5 +++-- lib/Options/GEODE.hs | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 lib/Options/GEODE.hs diff --git a/ghc-geode.cabal b/ghc-geode.cabal index 40f2170..08ed85c 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 7ff7bd1..1986f26 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 0000000..210e87b --- /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 ] -- GitLab