module Cardano.CLI.EraBased.Options.TopLevelCommands
  ( pCmds
  )
where

import           Cardano.Api (ShelleyBasedEra (..))

import           Cardano.CLI.Environment
import           Cardano.CLI.EraBased.Commands.TopLevelCommands
import           Cardano.CLI.EraBased.Options.Genesis
import           Cardano.CLI.EraBased.Options.Governance (pGovernanceCmds)
import           Cardano.CLI.EraBased.Options.Query
import           Cardano.CLI.EraBased.Options.StakeAddress
import           Cardano.CLI.EraBased.Options.StakePool
import           Cardano.CLI.EraBased.Options.TextView
import           Cardano.CLI.EraBased.Options.Transaction
import           Cardano.CLI.Options.Address
import           Cardano.CLI.Options.Key
import           Cardano.CLI.Options.Node

import           Data.Foldable
import           Data.Maybe
import           Options.Applicative (Parser)

pCmds :: ShelleyBasedEra era -> EnvCli -> Parser (Cmds era)
pCmds :: forall era. ShelleyBasedEra era -> EnvCli -> Parser (Cmds era)
pCmds ShelleyBasedEra era
era EnvCli
envCli = do
  [Parser (Cmds era)] -> Parser (Cmds era)
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum ([Parser (Cmds era)] -> Parser (Cmds era))
-> [Parser (Cmds era)] -> Parser (Cmds era)
forall a b. (a -> b) -> a -> b
$
    [Maybe (Parser (Cmds era))] -> [Parser (Cmds era)]
forall a. [Maybe a] -> [a]
catMaybes
      [ Parser (Cmds era) -> Maybe (Parser (Cmds era))
forall a. a -> Maybe a
Just (AddressCmds -> Cmds era
forall era. AddressCmds -> Cmds era
AddressCmds (AddressCmds -> Cmds era)
-> Parser AddressCmds -> Parser (Cmds era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> EnvCli -> Parser AddressCmds
pAddressCmds EnvCli
envCli)
      , Parser (Cmds era) -> Maybe (Parser (Cmds era))
forall a. a -> Maybe a
Just (KeyCmds -> Cmds era
forall era. KeyCmds -> Cmds era
KeyCmds (KeyCmds -> Cmds era) -> Parser KeyCmds -> Parser (Cmds era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser KeyCmds
pKeyCmds)
      , (GenesisCmds era -> Cmds era)
-> Parser (GenesisCmds era) -> Parser (Cmds era)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GenesisCmds era -> Cmds era
forall era. GenesisCmds era -> Cmds era
GenesisCmds (Parser (GenesisCmds era) -> Parser (Cmds era))
-> Maybe (Parser (GenesisCmds era)) -> Maybe (Parser (Cmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era -> EnvCli -> Maybe (Parser (GenesisCmds era))
forall era.
ShelleyBasedEra era -> EnvCli -> Maybe (Parser (GenesisCmds era))
pGenesisCmds ShelleyBasedEra era
era EnvCli
envCli
      , (GovernanceCmds era -> Cmds era)
-> Parser (GovernanceCmds era) -> Parser (Cmds era)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GovernanceCmds era -> Cmds era
forall era. GovernanceCmds era -> Cmds era
GovernanceCmds (Parser (GovernanceCmds era) -> Parser (Cmds era))
-> Maybe (Parser (GovernanceCmds era)) -> Maybe (Parser (Cmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era -> Maybe (Parser (GovernanceCmds era))
forall era.
ShelleyBasedEra era -> Maybe (Parser (GovernanceCmds era))
pGovernanceCmds ShelleyBasedEra era
era
      , Parser (Cmds era) -> Maybe (Parser (Cmds era))
forall a. a -> Maybe a
Just (NodeCmds -> Cmds era
forall era. NodeCmds -> Cmds era
NodeCmds (NodeCmds -> Cmds era) -> Parser NodeCmds -> Parser (Cmds era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NodeCmds
pNodeCmds)
      , (QueryCmds era -> Cmds era)
-> Parser (QueryCmds era) -> Parser (Cmds era)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap QueryCmds era -> Cmds era
forall era. QueryCmds era -> Cmds era
QueryCmds (Parser (QueryCmds era) -> Parser (Cmds era))
-> Maybe (Parser (QueryCmds era)) -> Maybe (Parser (Cmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era -> EnvCli -> Maybe (Parser (QueryCmds era))
forall era.
ShelleyBasedEra era -> EnvCli -> Maybe (Parser (QueryCmds era))
pQueryCmds ShelleyBasedEra era
era EnvCli
envCli
      , (StakeAddressCmds era -> Cmds era)
-> Parser (StakeAddressCmds era) -> Parser (Cmds era)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap StakeAddressCmds era -> Cmds era
forall era. StakeAddressCmds era -> Cmds era
StakeAddressCmds (Parser (StakeAddressCmds era) -> Parser (Cmds era))
-> Maybe (Parser (StakeAddressCmds era))
-> Maybe (Parser (Cmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era
-> EnvCli -> Maybe (Parser (StakeAddressCmds era))
forall era.
ShelleyBasedEra era
-> EnvCli -> Maybe (Parser (StakeAddressCmds era))
pStakeAddressCmds ShelleyBasedEra era
era EnvCli
envCli
      , (StakePoolCmds era -> Cmds era)
-> Parser (StakePoolCmds era) -> Parser (Cmds era)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap StakePoolCmds era -> Cmds era
forall era. StakePoolCmds era -> Cmds era
StakePoolCmds (Parser (StakePoolCmds era) -> Parser (Cmds era))
-> Maybe (Parser (StakePoolCmds era)) -> Maybe (Parser (Cmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era -> EnvCli -> Maybe (Parser (StakePoolCmds era))
forall era.
ShelleyBasedEra era -> EnvCli -> Maybe (Parser (StakePoolCmds era))
pStakePoolCmds ShelleyBasedEra era
era EnvCli
envCli
      , (TextViewCmds era -> Cmds era)
-> Parser (TextViewCmds era) -> Parser (Cmds era)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TextViewCmds era -> Cmds era
forall era. TextViewCmds era -> Cmds era
TextViewCmds (Parser (TextViewCmds era) -> Parser (Cmds era))
-> Maybe (Parser (TextViewCmds era)) -> Maybe (Parser (Cmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Parser (TextViewCmds era))
forall era. Maybe (Parser (TextViewCmds era))
pTextViewCmds
      , (TransactionCmds era -> Cmds era)
-> Parser (TransactionCmds era) -> Parser (Cmds era)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TransactionCmds era -> Cmds era
forall era. TransactionCmds era -> Cmds era
TransactionCmds (Parser (TransactionCmds era) -> Parser (Cmds era))
-> Maybe (Parser (TransactionCmds era))
-> Maybe (Parser (Cmds era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era
-> EnvCli -> Maybe (Parser (TransactionCmds era))
forall era.
ShelleyBasedEra era
-> EnvCli -> Maybe (Parser (TransactionCmds era))
pTransactionCmds ShelleyBasedEra era
era EnvCli
envCli
      ]