Skip to content

Commit 7927f6f

Browse files
authored
Merge pull request #6321 from IntersectMBO/mgalazyn/feature/cardano-submit-api-version
Add --version CLI argument to cardano-submit-api
2 parents fbd2915 + 6b0f802 commit 7927f6f

File tree

6 files changed

+108
-39
lines changed

6 files changed

+108
-39
lines changed

cardano-submit-api/app/Main.hs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
1+
{-# LANGUAGE LambdaCase #-}
2+
{-# LANGUAGE TemplateHaskell #-}
3+
14
module Main where
25

36
import Cardano.CLI.Environment (getEnvCli)
47
import qualified Cardano.Crypto.Init as Crypto
5-
import Cardano.TxSubmit (opts, runTxSubmitWebapi)
8+
import Cardano.Git.Rev (gitRev)
9+
import Cardano.TxSubmit (TxSubmitCommand (..), opts, runTxSubmitWebapi)
610

11+
import qualified Data.Text as T
12+
import Data.Version (showVersion)
713
import qualified Options.Applicative as Opt
14+
import System.Info (arch, compilerName, compilerVersion, os)
15+
16+
import Paths_cardano_submit_api (version)
817

918
main :: IO ()
1019
main = do
1120
Crypto.cryptoInit
1221

1322
envCli <- getEnvCli
1423

15-
runTxSubmitWebapi =<< Opt.execParser (opts envCli)
24+
Opt.execParser (opts envCli) >>= \case
25+
TxSubmitRun params -> runTxSubmitWebapi params
26+
TxSubmitVersion -> do
27+
putStrLn $
28+
mconcat
29+
[ "cardano-submit-api "
30+
, showVersion version
31+
, " - "
32+
, os
33+
, "-"
34+
, arch
35+
, " - "
36+
, compilerName
37+
, "-"
38+
, showVersion compilerVersion
39+
, "\ngit rev "
40+
, T.unpack $(gitRev)
41+
]

cardano-submit-api/cardano-submit-api.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ executable cardano-submit-api
8787
, optparse-applicative-fork
8888
, cardano-cli
8989
, cardano-crypto-class
90+
, cardano-git-rev ^>=0.2.2
9091
, cardano-submit-api
92+
, text
93+
other-modules: Paths_cardano_submit_api
94+
autogen-modules: Paths_cardano_submit_api
9195

9296
test-suite unit
9397
import: project-config

cardano-submit-api/src/Cardano/TxSubmit.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
module Cardano.TxSubmit
55
( runTxSubmitWebapi
66
, opts
7+
, TxSubmitCommand(..)
78
) where
89

910
import qualified Cardano.BM.Setup as Logging
1011
import Cardano.BM.Trace (Trace, logInfo)
1112
import qualified Cardano.BM.Trace as Logging
1213
import Cardano.TxSubmit.CLI.Parsers (opts)
13-
import Cardano.TxSubmit.CLI.Types (ConfigFile (unConfigFile), TxSubmitNodeParams (..))
14+
import Cardano.TxSubmit.CLI.Types (ConfigFile (unConfigFile), TxSubmitCommand (..),
15+
TxSubmitNodeParams (..))
1416
import Cardano.TxSubmit.Config (GenTxSubmitNodeConfig (..), ToggleLogging (..),
1517
TxSubmitNodeConfig, readTxSubmitNodeConfig)
1618
import Cardano.TxSubmit.Metrics (registerMetricsServer)

cardano-submit-api/src/Cardano/TxSubmit/CLI/Parsers.hs

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,87 @@
22

33
module Cardano.TxSubmit.CLI.Parsers
44
( opts
5-
, pTxSubmitNodeParams
5+
, pTxSubmit
66
, pConfigFile
77
, pSocketPath
8-
) where
8+
)
9+
where
910

1011
import Cardano.Api (File (..), SocketPath)
1112

1213
import Cardano.CLI.Environment (EnvCli (..))
1314
import Cardano.CLI.EraBased.Common.Option
14-
import Cardano.TxSubmit.CLI.Types (ConfigFile (..), TxSubmitNodeParams (..))
15+
import Cardano.TxSubmit.CLI.Types (ConfigFile (..), TxSubmitCommand (..),
16+
TxSubmitNodeParams (..))
1517
import Cardano.TxSubmit.Rest.Parsers (pWebserverConfig)
1618

17-
import Control.Applicative ((<**>))
19+
import Control.Applicative
1820
import Options.Applicative (Parser, ParserInfo)
1921
import qualified Options.Applicative as Opt
2022

21-
opts :: EnvCli -> ParserInfo TxSubmitNodeParams
23+
opts :: EnvCli -> ParserInfo TxSubmitCommand
2224
opts envCli =
23-
Opt.info (pTxSubmitNodeParams envCli <**> Opt.helper) $ mconcat
24-
[ Opt.fullDesc
25-
, Opt.progDesc "Cardano transaction submission web API."
25+
Opt.info (pTxSubmit envCli <**> Opt.helper) $
26+
mconcat
27+
[ Opt.fullDesc
28+
, Opt.progDesc "Cardano transaction submission web API."
29+
]
30+
31+
pTxSubmit :: EnvCli -> Parser TxSubmitCommand
32+
pTxSubmit envCli =
33+
asum
34+
[ TxSubmitRun
35+
<$> ( TxSubmitNodeParams
36+
<$> pConfigFile
37+
<*> pConsensusModeParams
38+
<*> pNetworkId envCli
39+
<*> pSocketPath'
40+
<*> pWebserverConfig 8090
41+
<*> pMetricsPort 8081
42+
)
43+
, pVersion
2644
]
2745

28-
pTxSubmitNodeParams :: EnvCli -> Parser TxSubmitNodeParams
29-
pTxSubmitNodeParams envCli = TxSubmitNodeParams
30-
<$> pConfigFile
31-
<*> pConsensusModeParams
32-
<*> pNetworkId envCli
33-
<*> pSocketPath'
34-
<*> pWebserverConfig 8090
35-
<*> pMetricsPort 8081
46+
pVersion :: Parser TxSubmitCommand
47+
pVersion =
48+
Opt.flag'
49+
TxSubmitVersion
50+
( Opt.long "version"
51+
<> Opt.help "Show the cardano-submit-api version"
52+
<> Opt.hidden
53+
)
3654

3755
pConfigFile :: Parser ConfigFile
38-
pConfigFile = ConfigFile <$> Opt.strOption
39-
( Opt.long "config"
40-
<> Opt.help "Path to the tx-submit web API configuration file"
41-
<> Opt.completer (Opt.bashCompleter "file")
42-
<> Opt.metavar "FILEPATH"
43-
)
56+
pConfigFile =
57+
ConfigFile
58+
<$> Opt.strOption
59+
( Opt.long "config"
60+
<> Opt.help "Path to the tx-submit web API configuration file"
61+
<> Opt.completer (Opt.bashCompleter "file")
62+
<> Opt.metavar "FILEPATH"
63+
)
4464

4565
pSocketPath' :: Parser SocketPath
4666
pSocketPath' =
47-
fmap File $ Opt.strOption $ mconcat
48-
[ Opt.long "socket-path"
49-
, Opt.help "Path to a cardano-node socket"
50-
, Opt.completer (Opt.bashCompleter "file")
51-
, Opt.metavar "FILEPATH"
52-
]
67+
fmap File $
68+
Opt.strOption $
69+
mconcat
70+
[ Opt.long "socket-path"
71+
, Opt.help "Path to a cardano-node socket"
72+
, Opt.completer (Opt.bashCompleter "file")
73+
, Opt.metavar "FILEPATH"
74+
]
5375

5476
pMetricsPort :: Int -> Parser Int
55-
pMetricsPort defaultValue = Opt.option Opt.auto
56-
( Opt.long "metrics-port"
57-
<> Opt.help ("Port for exposing metrics. If unavailable, the next free port is used. If no port can be allocated, "
58-
<> "the transaction submission API starts without metrics endpoint.")
59-
<> Opt.metavar "PORT"
60-
<> Opt.value defaultValue
61-
<> Opt.showDefault
62-
)
77+
pMetricsPort defaultValue =
78+
Opt.option
79+
Opt.auto
80+
( Opt.long "metrics-port"
81+
<> Opt.help
82+
( "Port for exposing metrics. If unavailable, the next free port is used. If no port can be allocated, "
83+
<> "the transaction submission API starts without metrics endpoint."
84+
)
85+
<> Opt.metavar "PORT"
86+
<> Opt.value defaultValue
87+
<> Opt.showDefault
88+
)

cardano-submit-api/src/Cardano/TxSubmit/CLI/Types.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
module Cardano.TxSubmit.CLI.Types
22
( ConfigFile (..)
33
, GenesisFile (..)
4+
, TxSubmitCommand(..)
45
, TxSubmitNodeParams (..)
56
) where
67

78
import Cardano.Api (ConsensusModeParams, NetworkId (..), SocketPath)
89

910
import Cardano.TxSubmit.Rest.Types (WebserverConfig)
1011

12+
data TxSubmitCommand
13+
= TxSubmitRun !TxSubmitNodeParams
14+
| TxSubmitVersion
15+
1116
-- | The product type of all command line arguments
1217
data TxSubmitNodeParams = TxSubmitNodeParams
1318
{ tspConfigFile :: !ConfigFile

flake.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@
146146
(set-git-rev cli)
147147
{passthru = {noGitRev = cli;};}
148148
;
149+
cardano-submit-api =
150+
let submit-api = project.exes.cardano-submit-api;
151+
in recursiveUpdate
152+
(set-git-rev submit-api)
153+
{passthru = {noGitRev = submit-api;};}
154+
;
149155
} // optionalAttrs (project.exes ? tx-generator) {
150156
tx-generator =
151157
let tx-gen = project.exes.tx-generator;

0 commit comments

Comments
 (0)