diff options
author | Kierán Meinhardt <kmein@posteo.de> | 2024-10-13 09:55:20 +0200 |
---|---|---|
committer | Kierán Meinhardt <kmein@posteo.de> | 2024-10-13 09:55:24 +0200 |
commit | 962db630a81a4040902c23c773df3069a48db0a3 (patch) | |
tree | 65c2208cd0fe98aa8979080cb22b84edc35253ef /cli | |
parent | 895772f1e76d0cdf12eba5a579ce889d585c9072 (diff) |
move Collection types to common
Diffstat (limited to 'cli')
-rw-r--r-- | cli/app/Main.hs | 45 | ||||
-rw-r--r-- | cli/cli.cabal | 1 |
2 files changed, 13 insertions, 33 deletions
diff --git a/cli/app/Main.hs b/cli/app/Main.hs index ef7a8ad..991eaa5 100644 --- a/cli/app/Main.hs +++ b/cli/app/Main.hs @@ -8,6 +8,7 @@ module Main where +import Collection import ACMS.API.REST.Collection qualified import Control.Applicative ((<**>)) import Data.Aeson qualified as J @@ -20,7 +21,7 @@ import Text.ParserCombinators.ReadPrec qualified as R import Text.Read (Read (..)) import Debug.Trace -data Args = Args +newtype Args = Args { cmd :: Cmd } @@ -44,28 +45,6 @@ data CollectionCmd | -- CollectionSchema Collection -newtype Collection = Collection T.Text - deriving (Read) - -data CollectionItem = CollectionItem - { collection :: Collection, - itemFileName :: T.Text - } - -instance Read CollectionItem where - readPrec = R.lift do - (Collection . T.pack -> collection) <- R.munch (/= '/') - _ <- R.string "/" - (T.pack -> itemFileName) <- do - itemFileName <- R.munch (liftA2 (&&) (/= '.') (/= '/')) - fileExt <- R.string ".json" - pure (itemFileName <> fileExt) - pure CollectionItem {..} - -instance Show CollectionItem where - show (CollectionItem {collection = Collection cn, itemFileName}) = - show (cn <> "/" <> itemFileName) - collectionCmd :: O.Parser Cmd collectionCmd = do fmap CollectionCmd . O.hsubparser . mconcat $ @@ -96,22 +75,22 @@ main = Args { cmd = CollectionCmd cmd } -> case cmd of - CollectionAdd (Collection cn) -> do + CollectionAdd collection -> do LB.putStr . J.encodePretty - =<< ACMS.API.REST.Collection.create cn + =<< ACMS.API.REST.Collection.create collection =<< J.throwDecode =<< LB.getContents - CollectionView CollectionItem {collection = Collection cn, itemFileName} -> + CollectionView collectionItem -> LB.putStr . J.encodePretty - =<< ACMS.API.REST.Collection.read cn itemFileName - CollectionDelete CollectionItem {collection = Collection cn, itemFileName} -> + =<< ACMS.API.REST.Collection.read collectionItem + CollectionDelete collectionItem -> LB.putStr . J.encodePretty - =<< ACMS.API.REST.Collection.delete cn itemFileName - CollectionEdit CollectionItem {collection = Collection cn, itemFileName} -> + =<< ACMS.API.REST.Collection.delete collectionItem + CollectionEdit collectionItem -> LB.putStr . J.encodePretty - =<< ACMS.API.REST.Collection.update cn itemFileName + =<< ACMS.API.REST.Collection.update collectionItem =<< J.throwDecode =<< LB.getContents - CollectionSchema (Collection cn) -> + CollectionSchema collection -> LB.putStr . J.encodePretty @J.Value - =<< ACMS.API.REST.Collection.schema cn + =<< ACMS.API.REST.Collection.schema collection diff --git a/cli/cli.cabal b/cli/cli.cabal index 4a21270..5617808 100644 --- a/cli/cli.cabal +++ b/cli/cli.cabal @@ -20,6 +20,7 @@ executable acms backend, base, bytestring, + common, filepath, optparse-applicative, sh, |