From c36c4cf37737ba972482a34c8df2b61a541e7f0a Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Wed, 19 Feb 2025 17:05:11 +0100 Subject: add `acms query` --- cli/app/Main.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'cli/app/Main.hs') diff --git a/cli/app/Main.hs b/cli/app/Main.hs index 4b166e7..12ba7c5 100644 --- a/cli/app/Main.hs +++ b/cli/app/Main.hs @@ -8,12 +8,14 @@ module Main where +import ACMS.API.Query qualified 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.Char8 qualified as LB +import Data.ByteString.Lazy.UTF8 qualified as LB import Data.Text qualified as T import Options.Applicative qualified as O @@ -24,13 +26,17 @@ newtype Args = Args args :: O.Parser Args args = Args <$> cmd_ -data Cmd = CollectionCmd CollectionCmd +data Cmd + = CollectionCmd CollectionCmd + | QueryCmd cmd_ :: O.Parser Cmd cmd_ = O.hsubparser . mconcat $ [ O.command "collection" . O.info collectionCmd $ - O.progDesc "Manage content collections" + O.progDesc "Manage content collections", + O.command "query" . O.info queryCmd $ + O.progDesc "Manage content through queries" ] data CollectionCmd @@ -68,6 +74,9 @@ collectionArg :: O.Parser Collection collectionArg = Collection . T.pack <$> O.strArgument (O.metavar "COLLECTION_NAME") +queryCmd :: O.Parser Cmd +queryCmd = pure QueryCmd + main :: IO () main = O.execParser (O.info (args <**> O.helper) O.idm) >>= \case @@ -94,3 +103,7 @@ main = CollectionSchema collection -> LB.putStr . J.encodePretty @J.Value =<< ACMS.API.REST.Collection.schema collection + Args {cmd = QueryCmd} -> + LB.putStr . J.encodePretty @J.Value + =<< ACMS.API.Query.query . LB.toString + =<< LB.getContents -- cgit v1.2.3