Support passing additional options to sandbox/navigator/json-api in daml start (#3002)

This should make `daml start` a bit more useful since you don’t have
to switch to starting all processes separately once you start
deviating from the defaults, e.g., I found myself wanting to specify a
custom ledger id during the hackathon. This is part 1 of ##2993.
This commit is contained in:
Moritz Kiefer 2019-09-24 18:39:16 +02:00 committed by GitHub
parent 1d593f2a16
commit 8ad74da20b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 6 deletions

View File

@ -44,6 +44,9 @@ data Command
, jsonApiCfg :: JsonApiConfig
, onStartM :: Maybe String
, waitForSignal :: WaitForSignal
, sandboxOptions :: SandboxOptions
, navigatorOptions :: NavigatorOptions
, jsonApiOptions :: JsonApiOptions
}
| Deploy { flags :: HostAndPortFlags }
| LedgerListParties { flags :: HostAndPortFlags, json :: JsonFlag }
@ -106,6 +109,9 @@ commandParser = subparser $ fold
<*> jsonApiCfg
<*> optional (option str (long "on-start" <> metavar "COMMAND" <> help "Command to run once sandbox and navigator are running."))
<*> (WaitForSignal <$> flagYesNoAuto "wait-for-signal" True "Wait for Ctrl+C or interrupt after starting servers." idm)
<*> (SandboxOptions <$> many (strOption (long "sandbox-option" <> metavar "SANDBOX_OPTION" <> help "Pass option to sandbox")))
<*> (NavigatorOptions <$> many (strOption (long "navigator-option" <> metavar "NAVIGATOR_OPTION" <> help "Pass option to navigator")))
<*> (JsonApiOptions <$> many (strOption (long "json-api-option" <> metavar "JSON_API_OPTION" <> help "Pass option to HTTP JSON API")))
deployCmdInfo = mconcat
[ progDesc $ concat
@ -215,7 +221,17 @@ runCommand New {..} = runNew targetFolder templateNameM []
runCommand Migrate {..} = runMigrate targetFolder pkgPathFrom pkgPathTo
runCommand Init {..} = runInit targetFolderM
runCommand ListTemplates = runListTemplates
runCommand Start {..} = runStart sandboxPortM startNavigator jsonApiCfg openBrowser onStartM waitForSignal
runCommand Start {..} =
runStart
sandboxPortM
startNavigator
jsonApiCfg
openBrowser
onStartM
waitForSignal
sandboxOptions
navigatorOptions
jsonApiOptions
runCommand Deploy {..} = runDeploy flags
runCommand LedgerListParties {..} = runLedgerListParties flags json
runCommand LedgerAllocateParties {..} = runLedgerAllocateParties flags parties

View File

@ -35,6 +35,9 @@ module DA.Daml.Helper.Run
, StartNavigator(..)
, WaitForSignal(..)
, DamlHelperError(..)
, SandboxOptions(..)
, NavigatorOptions(..)
, JsonApiOptions(..)
) where
import Control.Concurrent
@ -728,8 +731,32 @@ data JsonApiConfig = JsonApiConfig
-- | Whether `daml start` should wait for Ctrl+C or interrupt after starting servers.
newtype WaitForSignal = WaitForSignal Bool
runStart :: Maybe SandboxPort -> StartNavigator -> JsonApiConfig -> OpenBrowser -> Maybe String -> WaitForSignal -> IO ()
runStart sandboxPortM (StartNavigator shouldStartNavigator) (JsonApiConfig mbJsonApiPort) (OpenBrowser shouldOpenBrowser) onStartM (WaitForSignal shouldWaitForSignal) = withProjectRoot Nothing (ProjectCheck "daml start" True) $ \_ _ -> do
newtype SandboxOptions = SandboxOptions [String]
newtype NavigatorOptions = NavigatorOptions [String]
newtype JsonApiOptions = JsonApiOptions [String]
runStart
:: Maybe SandboxPort
-> StartNavigator
-> JsonApiConfig
-> OpenBrowser
-> Maybe String
-> WaitForSignal
-> SandboxOptions
-> NavigatorOptions
-> JsonApiOptions
-> IO ()
runStart
sandboxPortM
(StartNavigator shouldStartNavigator)
(JsonApiConfig mbJsonApiPort)
(OpenBrowser shouldOpenBrowser)
onStartM
(WaitForSignal shouldWaitForSignal)
(SandboxOptions sandboxOpts)
(NavigatorOptions navigatorOpts)
(JsonApiOptions jsonApiOpts)
= withProjectRoot Nothing (ProjectCheck "daml start" True) $ \_ _ -> do
let sandboxPort = fromMaybe defaultSandboxPort sandboxPortM
projectConfig <- getProjectConfig
darPath <- getDarPath
@ -738,12 +765,12 @@ runStart sandboxPortM (StartNavigator shouldStartNavigator) (JsonApiConfig mbJso
queryProjectConfig ["scenario"] projectConfig
doBuild
let scenarioArgs = maybe [] (\scenario -> ["--scenario", scenario]) mbScenario
withSandbox sandboxPort (darPath : scenarioArgs) $ \sandboxPh -> do
withNavigator' sandboxPh sandboxPort navigatorPort [] $ \navigatorPh -> do
withSandbox sandboxPort (darPath : scenarioArgs ++ sandboxOpts) $ \sandboxPh -> do
withNavigator' sandboxPh sandboxPort navigatorPort navigatorOpts $ \navigatorPh -> do
whenJust onStartM $ \onStart -> runProcess_ (shell onStart)
when (shouldStartNavigator && shouldOpenBrowser) $
void $ openBrowser (navigatorURL navigatorPort)
withJsonApi' sandboxPh sandboxPort [] $ \jsonApiPh -> do
withJsonApi' sandboxPh sandboxPort jsonApiOpts $ \jsonApiPh -> do
when shouldWaitForSignal $
void $ waitAnyCancel =<< mapM (async . waitExitCode) [navigatorPh,sandboxPh,jsonApiPh]

View File

@ -19,6 +19,8 @@ DAML Assistant (``daml``)
- Launch :doc:`DAML Studio </daml/daml-studio>`: ``daml studio``
- Launch :doc:`Sandbox </tools/sandbox>`, :doc:`Navigator </tools/navigator/index>` and the HTTP JSON API: ``daml start``
You can disable the HTTP JSON API by passing ``--json-api-port none`` to ``daml start``.
To specify additional options for sandbox/navigator/the HTTP JSON API you can use
``--sandbox-option=opt``, ``--navigator-option=opt`` and ``--json-api-option=opt``.
- Launch Sandbox: ``daml sandbox``
- Launch Navigator: ``daml navigator``
- Launch :doc:`Extractor </tools/extractor>`: ``daml extractor``

View File

@ -9,3 +9,6 @@ This page contains release notes for the SDK.
HEAD — ongoing
--------------
- [DAML Assistant] ``daml start`` now supports ``--sandbox-option=opt``, ``--navigator-option=opt``
and ``--json-api-option=opt`` to pass additional option to sandbox/navigator/json-api.
These flags can be specified multiple times.