@@ -12,7 +12,9 @@ module Cardano.Node.CLI (
1212 , TraceConstraints
1313 , ViewMode (.. )
1414 , fromProtocol
15- -- * Configuration
15+ -- * Common CLI
16+ , CommonCLI (.. )
17+ , parseCommonCLI
1618 , mergeConfiguration
1719 -- * Parsers
1820 , parseSystemStart
@@ -188,6 +190,45 @@ data ViewMode =
188190 LiveView -- Live mode with TUI
189191 | SimpleView -- Simple mode, just output text.
190192
193+ {- ------------------------------------------------------------------------------
194+ Common CLI
195+ -------------------------------------------------------------------------------}
196+
197+ -- | CLI Arguments common to all Cardano node flavors
198+ data CommonCLI = CommonCLI
199+ { cliGenesisFile :: ! (Last FilePath )
200+ , cliGenesisHash :: ! (Last Text )
201+ , cliStaticKeySigningKeyFile :: ! (Last FilePath )
202+ , cliStaticKeyDlgCertFile :: ! (Last FilePath )
203+ -- TODO cliPBftSigThd :: !(Last Double)
204+ -- TODO cliUpdate :: !PartialUpdate
205+ }
206+
207+ parseCommonCLI :: Parser CommonCLI
208+ parseCommonCLI =
209+ CommonCLI
210+ <$> lastStrOption
211+ ( long " genesis-file"
212+ <> metavar " FILEPATH"
213+ <> help " The filepath to the genesis file."
214+ )
215+ <*> lastStrOption
216+ ( long " genesis-hash"
217+ <> metavar " GENESIS-HASH"
218+ <> help " The genesis hash value."
219+ )
220+ <*> lastStrOption
221+ ( long " signing-key"
222+ <> metavar " FILEPATH"
223+ <> help " Path to the signing key."
224+ )
225+ <*> lastStrOption
226+ ( long " delegation-certificate"
227+ <> metavar " FILEPATH"
228+ <> help " Path to the delegation certificate."
229+ )
230+
231+
191232{- ------------------------------------------------------------------------------
192233 Configuration merging
193234-------------------------------------------------------------------------------}
@@ -197,25 +238,31 @@ data ViewMode =
197238-- We expect this process to become generic at some point.
198239mergeConfiguration
199240 :: PartialCardanoConfiguration
200- -> Last FilePath
201- -> Last Text
202- -> Last FilePath
203- -> Last FilePath
241+ -> CommonCLI
204242 -> PartialCardanoConfiguration
205- mergeConfiguration pcc lGenF lGenH lSKF lDlgF =
206- let PartialCore
207- { pcoGenesisFile
208- , pcoGenesisHash
209- , pcoStaticKeySigningKeyFile
210- , pcoStaticKeyDlgCertFile
211- } = pccCore pcc
212- in
213- pcc { pccCore = pccCore pcc <> mempty
214- { pcoGenesisFile = pcoGenesisFile <> lGenF
215- , pcoGenesisHash = pcoGenesisHash <> lGenH
216- , pcoStaticKeySigningKeyFile = pcoStaticKeySigningKeyFile <> lSKF
217- , pcoStaticKeyDlgCertFile = pcoStaticKeyDlgCertFile <> lDlgF
218- }}
243+ mergeConfiguration pcc cli =
244+ -- The beauty of this kind of configuration management (using trees of
245+ -- monoids) is that we can override individual config elements by simply
246+ -- merging an extra partial config on top. That extra partial config is
247+ -- built starting from mempty and setting the fields of interest.
248+ pcc <> commonCLIToPCC cli
249+ where
250+ commonCLIToPCC :: CommonCLI -> PartialCardanoConfiguration
251+ commonCLIToPCC CommonCLI {
252+ cliGenesisFile
253+ , cliGenesisHash
254+ , cliStaticKeySigningKeyFile
255+ , cliStaticKeyDlgCertFile
256+ } =
257+ mempty {
258+ pccCore = mempty {
259+ pcoGenesisFile = cliGenesisFile
260+ , pcoGenesisHash = cliGenesisHash
261+ , pcoStaticKeySigningKeyFile = cliStaticKeySigningKeyFile
262+ , pcoStaticKeyDlgCertFile = cliStaticKeyDlgCertFile
263+ -- TODO: cliPBftSigThd, cliUpdate
264+ }
265+ }
219266
220267{- ------------------------------------------------------------------------------
221268 Command parsers
0 commit comments