From 09809ae4df9ea2536bb6d9d6295cd3fdfd357945 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Wed, 19 Feb 2025 17:03:27 +0100 Subject: add `acms collection list` --- cli/app/Main.hs | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'cli') diff --git a/cli/app/Main.hs b/cli/app/Main.hs index 961f54f..4b166e7 100644 --- a/cli/app/Main.hs +++ b/cli/app/Main.hs @@ -8,12 +8,12 @@ module Main where -import Collection import ACMS.API.REST.Collection qualified +import Collection import Control.Applicative ((<**>)) import Data.Aeson qualified as J import Data.Aeson.Encode.Pretty qualified as J -import Data.ByteString.Lazy qualified as LB +import Data.ByteString.Lazy.Char8 qualified as LB import Data.Text qualified as T import Options.Applicative qualified as O @@ -39,7 +39,8 @@ data CollectionCmd | CollectionEdit CollectionItem | CollectionDelete CollectionItem | -- - CollectionSchema Collection + CollectionList Collection + | CollectionSchema Collection collectionCmd :: O.Parser Cmd collectionCmd = do @@ -53,6 +54,8 @@ collectionCmd = do O.command "delete" . O.info (CollectionDelete <$> collectionItemArg) $ O.progDesc "Delete an entity", -- + O.command "list" . O.info (CollectionList <$> collectionArg) $ + O.progDesc "List entities", O.command "schema" . O.info (CollectionSchema <$> collectionArg) $ O.progDesc "Show the collection's schema" ] @@ -68,25 +71,26 @@ collectionArg = main :: IO () main = O.execParser (O.info (args <**> O.helper) O.idm) >>= \case - Args - { cmd = CollectionCmd cmd - } -> case cmd of - CollectionAdd collection -> do - LB.putStr . J.encodePretty - =<< ACMS.API.REST.Collection.create collection - =<< J.throwDecode - =<< LB.getContents - CollectionView collectionItem -> - LB.putStr . J.encodePretty - =<< ACMS.API.REST.Collection.read collectionItem - CollectionDelete collectionItem -> - LB.putStr . J.encodePretty - =<< ACMS.API.REST.Collection.delete collectionItem - CollectionEdit collectionItem -> - LB.putStr . J.encodePretty - =<< ACMS.API.REST.Collection.update collectionItem - =<< J.throwDecode - =<< LB.getContents - CollectionSchema collection -> - LB.putStr . J.encodePretty @J.Value - =<< ACMS.API.REST.Collection.schema collection + Args {cmd = CollectionCmd cmd} -> case cmd of + CollectionAdd collection -> + LB.putStr . J.encodePretty + =<< ACMS.API.REST.Collection.create collection + =<< J.throwDecode + =<< LB.getContents + CollectionView collectionItem -> + LB.putStr . J.encodePretty + =<< ACMS.API.REST.Collection.read collectionItem + CollectionDelete collectionItem -> + LB.putStr . J.encodePretty + =<< ACMS.API.REST.Collection.delete collectionItem + CollectionEdit collectionItem -> + LB.putStr . J.encodePretty + =<< ACMS.API.REST.Collection.update collectionItem + =<< J.throwDecode + =<< LB.getContents + CollectionList collection -> + mapM_ (LB.putStrLn . J.encodePretty) + =<< ACMS.API.REST.Collection.list collection + CollectionSchema collection -> + LB.putStr . J.encodePretty @J.Value + =<< ACMS.API.REST.Collection.schema collection -- cgit v1.2.3