Skip to content

Commit

Permalink
Remove ls add and rm commands from cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jhbertra committed Feb 7, 2023
1 parent 9f761bf commit 33eee66
Show file tree
Hide file tree
Showing 11 changed files with 3 additions and 268 deletions.
36 changes: 2 additions & 34 deletions marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import qualified Data.ByteString.Lazy as LB
import Data.Foldable (asum)
import Language.Marlowe.Protocol.Sync.Client (marloweSyncClientPeer)
import Language.Marlowe.Protocol.Sync.Codec (codecMarloweSync)
import Language.Marlowe.Runtime.CLI.Command.Add (AddCommand, addCommandParser, runAddCommand)
import Language.Marlowe.Runtime.CLI.Command.Apply
( ApplyCommand
, advanceCommandParser
Expand All @@ -24,8 +23,6 @@ import Language.Marlowe.Runtime.CLI.Command.Apply
)
import Language.Marlowe.Runtime.CLI.Command.Create (CreateCommand, createCommandParser, runCreateCommand)
import Language.Marlowe.Runtime.CLI.Command.Log (LogCommand, logCommandParser, runLogCommand)
import Language.Marlowe.Runtime.CLI.Command.Ls (LsCommand, lsCommandParser, runLsCommand)
import Language.Marlowe.Runtime.CLI.Command.Rm (RmCommand, rmCommandParser, runRmCommand)
import Language.Marlowe.Runtime.CLI.Command.Submit (SubmitCommand, runSubmitCommand, submitCommandParser)
import Language.Marlowe.Runtime.CLI.Command.Tx (TxCommand)
import Language.Marlowe.Runtime.CLI.Command.Withdraw (WithdrawCommand, runWithdrawCommand, withdrawCommandParser)
Expand All @@ -36,8 +33,6 @@ import qualified Language.Marlowe.Runtime.CLI.Option as O
import Network.Protocol.Driver (RunClient, runClientPeerOverSocket)
import Network.Protocol.Job.Client (jobClientPeer)
import Network.Protocol.Job.Codec (codecJob)
import Network.Protocol.Query.Client (queryClientPeer)
import Network.Protocol.Query.Codec (codecQuery)
import Network.Socket (AddrInfo, HostName, PortNumber, SocketType(..), addrSocketType, defaultHints, getAddrInfo)
import Network.TypedProtocol (Peer, PeerRole(AsClient))
import Network.TypedProtocol.Codec (Codec)
Expand All @@ -47,46 +42,32 @@ import System.IO (hPutStrLn, stderr)
-- | Top-level options for running a command in the Marlowe Runtime CLI.
data Options = Options
{ historyHost :: !HostName
, historyCommandPort :: !PortNumber
, historyQueryPort :: !PortNumber
, historySyncPort :: !PortNumber
, discoveryHost :: !HostName
, discoveryQueryPort :: !PortNumber
, txHost :: !HostName
, txCommandPort :: !PortNumber
, cmd :: !Command
}

-- | A command for the Marlowe Runtime CLI.
data Command
= Add AddCommand
| Apply (TxCommand ApplyCommand)
= Apply (TxCommand ApplyCommand)
| Create (TxCommand CreateCommand)
| Log LogCommand
| Ls LsCommand
| Rm RmCommand
| Submit SubmitCommand
| Withdraw (TxCommand WithdrawCommand)

-- | Read options from the environment and the command line.
getOptions :: IO Options
getOptions = do
historyHostParser <- optParserWithEnvDefault O.historyHost
historyCommandPortParser <- optParserWithEnvDefault O.historyCommandPort
historyQueryPortParser <- optParserWithEnvDefault O.historyQueryPort
historySyncPortParser <- optParserWithEnvDefault O.historySyncPort
discoveryHostParser <- optParserWithEnvDefault O.discoveryHost
discoveryQueryPortParser <- optParserWithEnvDefault O.discoveryQueryPort
txHostParser <- optParserWithEnvDefault O.txHost
txCommandPortParser <- optParserWithEnvDefault O.txCommandPort
let
commandParser = asum
[ hsubparser $ mconcat
[ commandGroup "Contract history commands"
, command "add" $ Add <$> addCommandParser
, command "log" $ Log <$> logCommandParser
, command "ls" $ Ls <$> lsCommandParser
, command "rm" $ Rm <$> rmCommandParser
]
, hsubparser $ mconcat
[ commandGroup "Contract transaction commands"
Expand All @@ -105,11 +86,7 @@ getOptions = do
]
parser = Options
<$> historyHostParser
<*> historyCommandPortParser
<*> historyQueryPortParser
<*> historySyncPortParser
<*> discoveryHostParser
<*> discoveryQueryPortParser
<*> txHostParser
<*> txCommandPortParser
<*> commandParser
Expand All @@ -122,29 +99,20 @@ getOptions = do
-- | Run a command.
runCommand :: Command -> CLI ()
runCommand = \case
Add cmd -> runAddCommand cmd
Apply cmd -> runApplyCommand cmd
Create cmd -> runCreateCommand cmd
Log cmd -> runLogCommand cmd
Ls cmd -> runLsCommand cmd
Rm cmd -> runRmCommand cmd
Submit cmd -> runSubmitCommand cmd
Withdraw cmd -> runWithdrawCommand cmd

-- | Interpret a CLI action in IO using the provided options.
runCLIWithOptions :: STM () -> Options -> CLI a -> IO a
runCLIWithOptions sigInt Options{..} cli = do
historyJobAddr <- resolve historyHost historyCommandPort
historyQueryAddr <- resolve historyHost historyQueryPort
historySyncAddr <- resolve historyHost historySyncPort
discoveryQueryAddr <- resolve discoveryHost discoveryQueryPort
txJobAddr <- resolve txHost txCommandPort
runReaderT (runCLI cli) Env
{ envRunHistoryJobClient = runClientPeerOverSocket' "History job client failure" historyJobAddr codecJob jobClientPeer
, envRunHistoryQueryClient = runClientPeerOverSocket' "History query client failure" historyQueryAddr codecQuery queryClientPeer
, envRunHistorySyncClient = runClientPeerOverSocket' "History sync client failure" historySyncAddr codecMarloweSync marloweSyncClientPeer
{ envRunHistorySyncClient = runClientPeerOverSocket' "History sync client failure" historySyncAddr codecMarloweSync marloweSyncClientPeer
, envRunTxJobClient = runClientPeerOverSocket' "Tx client client failure" txJobAddr codecJob jobClientPeer
, envRunDiscoveryQueryClient = runClientPeerOverSocket' "Marlowe discovery query client failure" discoveryQueryAddr codecQuery queryClientPeer
, sigInt
}
where
Expand Down
27 changes: 0 additions & 27 deletions marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command/Add.hs

This file was deleted.

96 changes: 0 additions & 96 deletions marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command/Ls.hs

This file was deleted.

27 changes: 0 additions & 27 deletions marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command/Rm.hs

This file was deleted.

8 changes: 1 addition & 7 deletions marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ module Language.Marlowe.Runtime.CLI.Env

import Control.Concurrent.STM (STM)
import Language.Marlowe.Protocol.Sync.Client (MarloweSyncClient)
import Language.Marlowe.Runtime.Discovery.Api (DiscoveryQuery)
import Language.Marlowe.Runtime.History.Api (HistoryCommand, HistoryQuery)
import Language.Marlowe.Runtime.Transaction.Api (MarloweTxCommand)
import Network.Protocol.Driver (RunClient)
import Network.Protocol.Job.Client (JobClient)
import Network.Protocol.Query.Client (QueryClient)

-- | The environment for the Marlowe Runtime CLI.
data Env m = Env
{ envRunHistoryJobClient :: !(RunClient m (JobClient HistoryCommand))
, envRunHistoryQueryClient :: !(RunClient m (QueryClient HistoryQuery))
, envRunHistorySyncClient :: !(RunClient m MarloweSyncClient)
, envRunDiscoveryQueryClient :: !(RunClient m (QueryClient DiscoveryQuery))
{ envRunHistorySyncClient :: !(RunClient m MarloweSyncClient)
, envRunTxJobClient :: !(RunClient m (JobClient MarloweTxCommand))
, sigInt :: STM ()
}
32 changes: 0 additions & 32 deletions marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ import Control.Monad.Trans.Reader (ReaderT, ask, asks, local)
import Data.Void (Void)
import Language.Marlowe.Protocol.Sync.Client (MarloweSyncClient, hoistMarloweSyncClient)
import Language.Marlowe.Runtime.CLI.Env (Env(..))
import Language.Marlowe.Runtime.Discovery.Api (DiscoveryQuery)
import Language.Marlowe.Runtime.History.Api (HistoryCommand, HistoryQuery)
import Language.Marlowe.Runtime.Transaction.Api (MarloweTxCommand)
import Network.Protocol.Job.Client (JobClient, hoistJobClient, liftCommand)
import Network.Protocol.Query.Client (QueryClient, hoistQueryClient, liftQuery)
import Options.Applicative (Alternative)
import System.Exit (die)

Expand Down Expand Up @@ -48,20 +45,6 @@ asksEnv = CLI . asks
localEnv :: (Env IO -> Env IO) -> CLI a -> CLI a
localEnv f = CLI . local f . runCLI

-- | Run a History Job client.
runHistoryJobClient :: JobClient HistoryCommand CLI a -> CLI a
runHistoryJobClient client = do
Env{..} <- askEnv
liftBaseWith \runInBase ->
envRunHistoryJobClient $ hoistJobClient runInBase client

-- | Run a History Query client.
runHistoryQueryClient :: QueryClient HistoryQuery CLI a -> CLI a
runHistoryQueryClient client = do
Env{..} <- askEnv
liftBaseWith \runInBase ->
envRunHistoryQueryClient $ hoistQueryClient runInBase client

-- | Run a Marlowe Sync client.
runHistorySyncClient :: MarloweSyncClient CLI a -> CLI a
runHistorySyncClient client = do
Expand All @@ -76,21 +59,6 @@ runTxJobClient client = do
liftBaseWith \runInBase ->
envRunTxJobClient $ hoistJobClient runInBase client

-- | Run a Discovery Query client.
runDiscoveryQueryClient :: QueryClient DiscoveryQuery CLI a -> CLI a
runDiscoveryQueryClient client = do
Env{..} <- askEnv
liftBaseWith \runInBase ->
envRunDiscoveryQueryClient $ hoistQueryClient runInBase client

-- | Run a simple History command.
runHistoryCommand :: HistoryCommand Void err result -> CLI (Either err result)
runHistoryCommand = runHistoryJobClient . liftCommand

-- | Run a simple History query.
queryHistory :: HistoryQuery Void err results -> CLI (Either err results)
queryHistory = runHistoryQueryClient . liftQuery

-- | Run a simple Tx command.
runTxCommand :: MarloweTxCommand Void err result -> CLI (Either err result)
runTxCommand = runTxJobClient . liftCommand
Expand Down
6 changes: 0 additions & 6 deletions marlowe-runtime/doc/marlowe.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ The `marlowe` executable provides a command-line interface to interacting with M
- Submitting transactions
- [Submit a signed transaction to the node](marlowe/submit.md)
- Querying history
- [List the contracts being tracked](marlowe/ls.md)
- [Add a contract to the set of tracked contracts](marlowe/add.md)
- [Remove a contract from the set of tracked contracts](marlowe/rm.md)
- [Output the History of a contract](marlowe/log.md)

```console
Expand Down Expand Up @@ -61,10 +58,7 @@ Available options:
MARLOWE_RT_TX_COMMAND_PORT (default: 3723)

Contract history commands
add Start managing a new contract
log Display the history of a contract
ls List managed contracts
rm Stop managing a contract

Contract transaction commands
apply Apply inputs to a contract
Expand Down
11 changes: 0 additions & 11 deletions marlowe-runtime/doc/marlowe/add.md

This file was deleted.

13 changes: 0 additions & 13 deletions marlowe-runtime/doc/marlowe/ls.md

This file was deleted.

Loading

0 comments on commit 33eee66

Please sign in to comment.