aboutsummaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2025-02-19 17:05:11 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2025-02-19 19:26:11 +0100
commitc36c4cf37737ba972482a34c8df2b61a541e7f0a (patch)
tree5682b53cd5b9d03fa56a4a11ba12f4916dd69ea3 /cli
parent09809ae4df9ea2536bb6d9d6295cd3fdfd357945 (diff)
add `acms query`
Diffstat (limited to 'cli')
-rw-r--r--cli/app/Main.hs17
-rw-r--r--cli/cli.cabal3
2 files changed, 17 insertions, 3 deletions
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
diff --git a/cli/cli.cabal b/cli/cli.cabal
index 5617808..3d0934e 100644
--- a/cli/cli.cabal
+++ b/cli/cli.cabal
@@ -24,4 +24,5 @@ executable acms
filepath,
optparse-applicative,
sh,
- text
+ text,
+ utf8-string