aboutsummaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/app/Main.hs45
-rw-r--r--cli/cli.cabal1
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,