Skip to content

Commit

Permalink
Merge pull request #890 from IntersectMBO/smelc/share-code-in-filepat…
Browse files Browse the repository at this point in the history
…hs-parsers

Options: avoid code duplication
  • Loading branch information
smelc authored Sep 12, 2024
2 parents 72b97aa + 108c1c2 commit 39af17e
Show file tree
Hide file tree
Showing 723 changed files with 5,564 additions and 5,667 deletions.
492 changes: 87 additions & 405 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs

Large diffs are not rendered by default.

26 changes: 5 additions & 21 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,7 @@ pGenesisCreateStaked sbe envCli =
where
pRelayJsonFp :: Parser FilePath
pRelayJsonFp =
Opt.strOption $
mconcat
[ Opt.long "relay-specification-file"
, Opt.metavar "FILE"
, Opt.help "JSON file that specifies the relays of each stake pool."
, Opt.completer (Opt.bashCompleter "file")
]
parseFilePath "relay-specification-file" "JSON file that specifies the relays of each stake pool."

pGenesisCreateTestNetData :: ShelleyBasedEra era -> EnvCli -> Parser (GenesisCmds era)
pGenesisCreateTestNetData sbe envCli =
Expand All @@ -241,13 +235,9 @@ pGenesisCreateTestNetData sbe envCli =
<*> pOutputDir
where
pSpecFile eraStr =
Opt.strOption $
mconcat
[ Opt.long $ "spec-" <> eraStr
, Opt.metavar "FILE"
, Opt.help $
"The " <> eraStr <> " specification file to use as input. A default one is generated if omitted."
]
parseFilePath
("spec-" <> eraStr)
("The " <> eraStr <> " specification file to use as input. A default one is generated if omitted.")
pNumGenesisKeys =
Opt.option integralReader $
mconcat
Expand Down Expand Up @@ -348,13 +338,7 @@ pGenesisCreateTestNetData sbe envCli =
]
pRelays :: Parser FilePath
pRelays =
Opt.strOption $
mconcat
[ Opt.long "relays"
, Opt.metavar "FILE"
, Opt.help "JSON file specifying the relays of each stake pool."
, Opt.completer (Opt.bashCompleter "file")
]
parseFilePath "relays" "JSON file specifying the relays of each stake pool."
pOutputDir =
Opt.strOption $
mconcat
Expand Down
38 changes: 6 additions & 32 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,12 @@ pByronKeyFile =

pByronSigningKeyFile :: Parser (SigningKeyFile In)
pByronSigningKeyFile =
fmap File $
Opt.strOption $
mconcat
[ Opt.long "byron-signing-key-file"
, Opt.metavar "FILE"
, Opt.help "Input filepath of the Byron-format signing key."
, Opt.completer (Opt.bashCompleter "file")
]
File <$> parseFilePath "byron-signing-key-file" "Input filepath of the Byron-format signing key."

pByronVerificationKeyFile :: Parser (VerificationKeyFile In)
pByronVerificationKeyFile =
fmap File $
Opt.strOption $
mconcat
[ Opt.long "byron-verification-key-file"
, Opt.metavar "FILE"
, Opt.help "Input filepath of the Byron-format verification key."
, Opt.completer (Opt.bashCompleter "file")
]
File
<$> parseFilePath "byron-verification-key-file" "Input filepath of the Byron-format verification key."

pKeyConvertByronGenesisKeyCmd :: Parser (KeyCmds era)
pKeyConvertByronGenesisKeyCmd =
Expand Down Expand Up @@ -246,25 +233,12 @@ pITNKeyFIle =

pITNSigningKeyFile :: Parser (SomeKeyFile direction)
pITNSigningKeyFile =
fmap (ASigningKeyFile . File) $
Opt.strOption $
mconcat
[ Opt.long "itn-signing-key-file"
, Opt.metavar "FILE"
, Opt.help "Filepath of the ITN signing key."
, Opt.completer (Opt.bashCompleter "file")
]
ASigningKeyFile . File <$> parseFilePath "itn-signing-key-file" "Filepath of the ITN signing key."

pITNVerificationKeyFile :: Parser (SomeKeyFile direction)
pITNVerificationKeyFile =
fmap (AVerificationKeyFile . File) $
Opt.strOption $
mconcat
[ Opt.long "itn-verification-key-file"
, Opt.metavar "FILE"
, Opt.help "Filepath of the ITN verification key."
, Opt.completer (Opt.bashCompleter "file")
]
AVerificationKeyFile . File
<$> parseFilePath "itn-verification-key-file" "Filepath of the ITN verification key."

pKeyConvertCardanoAddressKeyCmd :: Parser (KeyCmds era)
pKeyConvertCardanoAddressKeyCmd =
Expand Down
8 changes: 1 addition & 7 deletions cardano-cli/src/Cardano/CLI/Legacy/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,13 +1187,7 @@ pGenesisCmds envCli =

pRelayJsonFp :: Parser FilePath
pRelayJsonFp =
Opt.strOption $
mconcat
[ Opt.long "relay-specification-file"
, Opt.metavar "FILE"
, Opt.help "JSON file specified the relays of each stake pool."
, Opt.completer (Opt.bashCompleter "file")
]
parseFilePath "relay-specification-file" "JSON file specified the relays of each stake pool."

pInitialSupplyNonDelegated :: Parser (Maybe Coin)
pInitialSupplyNonDelegated =
Expand Down
39 changes: 7 additions & 32 deletions cardano-cli/src/Cardano/CLI/Legacy/Options/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,12 @@ pByronKeyFile =

pByronSigningKeyFile :: Parser (SigningKeyFile In)
pByronSigningKeyFile =
fmap File $
Opt.strOption $
mconcat
[ Opt.long "byron-signing-key-file"
, Opt.metavar "FILE"
, Opt.help "Input filepath of the Byron-format signing key."
, Opt.completer (Opt.bashCompleter "file")
]
File <$> parseFilePath "byron-signing-key-file" "Input filepath of the Byron-format signing key."

pByronVerificationKeyFile :: Parser (VerificationKeyFile In)
pByronVerificationKeyFile =
fmap File $
Opt.strOption $
mconcat
[ Opt.long "byron-verification-key-file"
, Opt.metavar "FILE"
, Opt.help "Input filepath of the Byron-format verification key."
, Opt.completer (Opt.bashCompleter "file")
]
File
<$> parseFilePath "byron-verification-key-file" "Input filepath of the Byron-format verification key."

pKeyConvertByronGenesisVKeyCmd :: Parser LegacyKeyCmds
pKeyConvertByronGenesisVKeyCmd =
Expand Down Expand Up @@ -222,25 +209,13 @@ pITNKeyFIle =

pITNSigningKeyFile :: Parser (SomeKeyFile direction)
pITNSigningKeyFile =
fmap (ASigningKeyFile . File) $
Opt.strOption $
mconcat
[ Opt.long "itn-signing-key-file"
, Opt.metavar "FILE"
, Opt.help "Filepath of the ITN signing key."
, Opt.completer (Opt.bashCompleter "file")
]
ASigningKeyFile . File
<$> parseFilePath "itn-signing-key-file" "Filepath of the ITN signing key."

pITNVerificationKeyFile :: Parser (SomeKeyFile direction)
pITNVerificationKeyFile =
fmap (AVerificationKeyFile . File) $
Opt.strOption $
mconcat
[ Opt.long "itn-verification-key-file"
, Opt.metavar "FILE"
, Opt.help "Filepath of the ITN verification key."
, Opt.completer (Opt.bashCompleter "file")
]
AVerificationKeyFile . File
<$> parseFilePath "itn-verification-key-file" "Filepath of the ITN verification key."

pKeyConvertCardanoAddressKeyCmd :: Parser LegacyKeyCmds
pKeyConvertCardanoAddressKeyCmd =
Expand Down
10 changes: 2 additions & 8 deletions cardano-cli/src/Cardano/CLI/Options/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,5 @@ pDebugCmds envCli =

pNodeConfigurationFileIn :: Parser (NodeConfigFile In)
pNodeConfigurationFileIn =
fmap File $
Opt.strOption $
mconcat
[ Opt.long "node-configuration-file"
, Opt.metavar "FILE"
, Opt.help "Input filepath of the node configuration file."
, Opt.completer (Opt.bashCompleter "file")
]
File
<$> parseFilePath "node-configuration-file" "Input filepath of the node configuration file."
Loading

0 comments on commit 39af17e

Please sign in to comment.