diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/CHANGELOG.md | 5 | ||||
-rw-r--r-- | cli/LICENSE | 26 | ||||
-rw-r--r-- | cli/app/Main.hs | 92 | ||||
-rw-r--r-- | cli/cli.cabal | 27 |
4 files changed, 0 insertions, 150 deletions
diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md deleted file mode 100644 index b733b96..0000000 --- a/cli/CHANGELOG.md +++ /dev/null @@ -1,5 +0,0 @@ -# Revision history for cli - -## 0.1.0.0 -- YYYY-mm-dd - -* First version. Released on an unsuspecting world. diff --git a/cli/LICENSE b/cli/LICENSE deleted file mode 100644 index 9128a61..0000000 --- a/cli/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2024, Alexander Foremny -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the - distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cli/app/Main.hs b/cli/app/Main.hs deleted file mode 100644 index 961f54f..0000000 --- a/cli/app/Main.hs +++ /dev/null @@ -1,92 +0,0 @@ -{-# LANGUAGE ApplicativeDo #-} -{-# LANGUAGE BlockArguments #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE NoFieldSelectors #-} - -module Main where - -import Collection -import ACMS.API.REST.Collection qualified -import Control.Applicative ((<**>)) -import Data.Aeson qualified as J -import Data.Aeson.Encode.Pretty qualified as J -import Data.ByteString.Lazy 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 - -cmd_ :: O.Parser Cmd -cmd_ = - O.hsubparser . mconcat $ - [ O.command "collection" . O.info collectionCmd $ - O.progDesc "Manage content collections" - ] - -data CollectionCmd - = CollectionAdd Collection - | CollectionView CollectionItem - | CollectionEdit CollectionItem - | CollectionDelete CollectionItem - | -- - 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 "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") - -main :: IO () -main = - O.execParser (O.info (args <**> O.helper) O.idm) >>= \case - Args - { cmd = CollectionCmd cmd - } -> case cmd of - CollectionAdd collection -> do - 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 - CollectionSchema collection -> - LB.putStr . J.encodePretty @J.Value - =<< ACMS.API.REST.Collection.schema collection diff --git a/cli/cli.cabal b/cli/cli.cabal deleted file mode 100644 index 5617808..0000000 --- a/cli/cli.cabal +++ /dev/null @@ -1,27 +0,0 @@ -cabal-version: 3.4 -name: cli -version: 0.1.0.0 -license: BSD-2-Clause -license-file: LICENSE -maintainer: aforemny@posteo.de -author: Alexander Foremny -build-type: Simple -extra-doc-files: CHANGELOG.md - -executable acms - main-is: Main.hs - hs-source-dirs: app - other-modules: - default-language: GHC2021 - ghc-options: -Wall - build-depends: - aeson, - aeson-pretty, - backend, - base, - bytestring, - common, - filepath, - optparse-applicative, - sh, - text |