rename collection(item) types
This commit is contained in:
@@ -25,7 +25,7 @@ data Args = Args
|
||||
args :: O.Parser Args
|
||||
args = Args <$> cmd_
|
||||
|
||||
data Cmd = Collection CollectionCmd
|
||||
data Cmd = CollectionCmd CollectionCmd
|
||||
|
||||
cmd_ :: O.Parser Cmd
|
||||
cmd_ =
|
||||
@@ -35,36 +35,36 @@ cmd_ =
|
||||
]
|
||||
|
||||
data CollectionCmd
|
||||
= CollectionAdd CollectionName
|
||||
| CollectionView CollectionPath
|
||||
| CollectionEdit CollectionPath
|
||||
| CollectionDelete CollectionPath
|
||||
= CollectionAdd Collection
|
||||
| CollectionView CollectionItem
|
||||
| CollectionEdit CollectionItem
|
||||
| CollectionDelete CollectionItem
|
||||
|
||||
newtype CollectionName = CollectionName T.Text
|
||||
newtype Collection = Collection T.Text
|
||||
deriving (Read)
|
||||
|
||||
data CollectionPath = CollectionPath
|
||||
{ collectionName :: CollectionName,
|
||||
data CollectionItem = CollectionItem
|
||||
{ collectionName :: Collection,
|
||||
fileName :: T.Text
|
||||
}
|
||||
|
||||
instance Read CollectionPath where
|
||||
instance Read CollectionItem where
|
||||
readPrec = R.lift do
|
||||
(CollectionName . T.pack -> collectionName) <- R.munch (/= '/')
|
||||
(Collection . T.pack -> collectionName) <- R.munch (/= '/')
|
||||
_ <- R.string "/"
|
||||
(T.pack -> fileName) <- do
|
||||
fileName <- R.munch (liftA2 (&&) (/= '.') (/= '/'))
|
||||
fileExt <- R.string ".json"
|
||||
pure (fileName <> fileExt)
|
||||
pure CollectionPath {..}
|
||||
pure CollectionItem {..}
|
||||
|
||||
instance Show CollectionPath where
|
||||
show (CollectionPath {collectionName = CollectionName cn, fileName}) =
|
||||
instance Show CollectionItem where
|
||||
show (CollectionItem {collectionName = Collection cn, fileName}) =
|
||||
show (cn <> "/" <> fileName)
|
||||
|
||||
collectionCmd :: O.Parser Cmd
|
||||
collectionCmd = do
|
||||
fmap Collection . O.hsubparser . mconcat $
|
||||
fmap CollectionCmd . O.hsubparser . mconcat $
|
||||
[ O.command "add" . O.info (CollectionAdd <$> collectionNameArg) $
|
||||
O.progDesc "Add an entity"
|
||||
, O.command "view" . O.info (CollectionView <$> collectionPathArg) $
|
||||
@@ -75,32 +75,32 @@ collectionCmd = do
|
||||
O.progDesc "Delete an entity"
|
||||
]
|
||||
|
||||
collectionPathArg :: O.Parser CollectionPath
|
||||
collectionPathArg :: O.Parser CollectionItem
|
||||
collectionPathArg =
|
||||
O.argument O.auto (O.metavar "COLLECTION_PATH")
|
||||
|
||||
collectionNameArg :: O.Parser CollectionName
|
||||
collectionNameArg :: O.Parser Collection
|
||||
collectionNameArg =
|
||||
CollectionName . T.pack <$> O.strArgument (O.metavar "COLLECTION_NAME")
|
||||
Collection . T.pack <$> O.strArgument (O.metavar "COLLECTION_NAME")
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
O.execParser (O.info (args <**> O.helper) O.idm) >>= \case
|
||||
Args
|
||||
{ cmd = Collection cmd
|
||||
{ cmd = CollectionCmd cmd
|
||||
} -> case cmd of
|
||||
CollectionAdd (CollectionName cn) -> do
|
||||
CollectionAdd (Collection cn) -> do
|
||||
print
|
||||
=<< ACMS.API.REST.Collection.create cn
|
||||
=<< J.throwDecode
|
||||
=<< LB.getContents
|
||||
CollectionView CollectionPath {collectionName = CollectionName cn, fileName} ->
|
||||
CollectionView CollectionItem {collectionName = Collection cn, fileName} ->
|
||||
print
|
||||
=<< ACMS.API.REST.Collection.read cn fileName
|
||||
CollectionDelete CollectionPath {collectionName = CollectionName cn, fileName}->
|
||||
CollectionDelete CollectionItem {collectionName = Collection cn, fileName}->
|
||||
print
|
||||
=<< ACMS.API.REST.Collection.delete cn fileName
|
||||
CollectionEdit CollectionPath {collectionName = CollectionName cn, fileName}->
|
||||
CollectionEdit CollectionItem {collectionName = Collection cn, fileName}->
|
||||
print
|
||||
=<< ACMS.API.REST.Collection.update cn fileName
|
||||
=<< J.throwDecode
|
||||
|
||||
Reference in New Issue
Block a user