aboutsummaryrefslogtreecommitdiffstats
path: root/cli/app
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2025-02-20 12:29:35 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2025-02-20 18:36:23 +0100
commitcaf72faccc04e647c27e1b5eef85c515949d8210 (patch)
treeec32dda7b87c12712307d2d101368fed5888d4b9 /cli/app
parent3c64b52017e7c16da0d017c033c77eee5d7a4340 (diff)
consolidate `backend, cli, common` -> `acms`
Diffstat (limited to 'cli/app')
-rw-r--r--cli/app/Main.hs109
1 files changed, 0 insertions, 109 deletions
diff --git a/cli/app/Main.hs b/cli/app/Main.hs
deleted file mode 100644
index 12ba7c5..0000000
--- a/cli/app/Main.hs
+++ /dev/null
@@ -1,109 +0,0 @@
-{-# LANGUAGE ApplicativeDo #-}
-{-# LANGUAGE BlockArguments #-}
-{-# LANGUAGE LambdaCase #-}
-{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE RecordWildCards #-}
-{-# LANGUAGE ViewPatterns #-}
-{-# LANGUAGE NoFieldSelectors #-}
-
-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
-
-newtype Args = Args
- { cmd :: Cmd
- }
-
-args :: O.Parser Args
-args = Args <$> cmd_
-
-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.command "query" . O.info queryCmd $
- O.progDesc "Manage content through queries"
- ]
-
-data CollectionCmd
- = CollectionAdd Collection
- | CollectionView CollectionItem
- | CollectionEdit CollectionItem
- | CollectionDelete CollectionItem
- | --
- CollectionList Collection
- | CollectionSchema Collection
-
-collectionCmd :: O.Parser Cmd
-collectionCmd = do
- fmap CollectionCmd . O.hsubparser . mconcat $
- [ O.command "add" . O.info (CollectionAdd <$> collectionArg) $
- O.progDesc "Add an entity",
- O.command "view" . O.info (CollectionView <$> collectionItemArg) $
- O.progDesc "View an entity",
- O.command "edit" . O.info (CollectionEdit <$> collectionItemArg) $
- O.progDesc "Edit an entity",
- 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"
- ]
-
-collectionItemArg :: O.Parser CollectionItem
-collectionItemArg =
- O.argument O.auto (O.metavar "COLLECTION_PATH")
-
-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
- 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
- Args {cmd = QueryCmd} ->
- LB.putStr . J.encodePretty @J.Value
- =<< ACMS.API.Query.query . LB.toString
- =<< LB.getContents