Skip to content

Commit

Permalink
Add clusterDir command line option to the local-cluster exe
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed May 3, 2024
1 parent 5abf6eb commit c7ec53e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
19 changes: 12 additions & 7 deletions lib/local-cluster/exe/local-cluster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,15 @@ main = withUtf8 $ do
$ Just
$ mkRelDirOf
$ Cluster.clusterEraToString clusterEra
CommandLineOptions{clusterConfigsDir} <- parseCommandLineOptions
CommandLineOptions{clusterConfigsDir, clusterDir} <- parseCommandLineOptions
evalContT $ do
-- Create a temporary directory for the cluster
clusterPath <- ContT $ withSystemTempDir tr "test-cluster" skipCleanup
clusterPath <-
case clusterDir of
Just path -> pure path
Nothing ->
fmap (DirOf . absDir) $
ContT $ withSystemTempDir tr "test-cluster" skipCleanup
-- Start the faucet
faucetClientEnv <- ContT withFaucet
maryAllegraFunds <-
Expand All @@ -234,7 +239,7 @@ main = withUtf8 $ do
{ cfgStakePools = Cluster.defaultPoolConfigs
, cfgLastHardFork = clusterEra
, cfgNodeLogging
, cfgClusterDir = DirOf (absDir clusterPath)
, cfgClusterDir = clusterPath
, cfgClusterConfigs = clusterConfigsDir
, cfgTestnetMagic = Cluster.TestnetMagic 42
, cfgShelleyGenesisMods = [over #sgSlotLength \_ -> 0.2]
Expand All @@ -257,20 +262,20 @@ main = withUtf8 $ do
Right p -> pure p

-- Start the wallet
let clusterDir = absDir clusterPath
let walletDir = clusterDir </> relDir "wallet"
let clusterDirPath = absDirOf clusterPath
let walletDir = clusterDirPath </> relDir "wallet"
liftIO $ createDirectoryIfMissing True $ toFilePath walletDir
let walletProcessConfig =
WC.WalletProcessConfig
{ WC.walletDir = DirOf walletDir
, WC.walletNodeApi = NC.NodeApi nodeSocket
, WC.walletDatabase = DirOf $ clusterDir </> relDir "db"
, WC.walletDatabase = DirOf $ clusterDirPath </> relDir "db"
, WC.walletListenHost = Nothing
, WC.walletListenPort = Nothing
, WC.walletByronGenesisForTestnet =
Just
$ FileOf
$ clusterDir
$ clusterDirPath
</> relFile "byron-genesis.json"
}
(_walletInstance, _walletApi) <-
Expand Down
21 changes: 18 additions & 3 deletions lib/local-cluster/lib/Cardano/Wallet/Launch/Cluster/CommandLine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Options.Applicative
, info
, long
, metavar
, optional
, progDesc
, strOption
, (<**>)
Expand All @@ -31,16 +32,20 @@ import System.Path
( absRel
)

newtype CommandLineOptions = CommandLineOptions
{clusterConfigsDir :: DirOf "cluster-configs"}
data CommandLineOptions = CommandLineOptions
{ clusterConfigsDir :: DirOf "cluster-configs"
, clusterDir :: Maybe (DirOf "cluster")
}
deriving stock (Show)

parseCommandLineOptions :: IO CommandLineOptions
parseCommandLineOptions = do
absolutizer <- newAbsolutizer
execParser
$ info
( fmap CommandLineOptions (clusterConfigsDirParser absolutizer)
( CommandLineOptions
<$> clusterConfigsDirParser absolutizer
<*> clusterDirParser absolutizer
<**> helper
)
(progDesc "Local Cluster for testing")
Expand All @@ -53,3 +58,13 @@ clusterConfigsDirParser (Absolutizer absOf) =
<> metavar "LOCAL_CLUSTER_CONFIGS"
<> help "Path to the local cluster configuration directory"
)

clusterDirParser :: Absolutizer -> Parser (Maybe (DirOf "cluster"))
clusterDirParser (Absolutizer absOf) =
optional
$ DirOf . absOf . absRel
<$> strOption
( long "cluster"
<> metavar "LOCAL_CLUSTER"
<> help "Path to the local cluster directory"
)

0 comments on commit c7ec53e

Please sign in to comment.