Skip to content

Commit

Permalink
Support passing additional options to sandbox/navigator/json-api in d…
Browse files Browse the repository at this point in the history
…aml start (digital-asset#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 #digital-asset#2993.
  • Loading branch information
cocreature authored Sep 24, 2019
1 parent 1d593f2 commit 8ad74da
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
18 changes: 17 additions & 1 deletion daml-assistant/daml-helper/src/DA/Daml/Helper/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
37 changes: 32 additions & 5 deletions daml-assistant/daml-helper/src/DA/Daml/Helper/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module DA.Daml.Helper.Run
, StartNavigator(..)
, WaitForSignal(..)
, DamlHelperError(..)
, SandboxOptions(..)
, NavigatorOptions(..)
, JsonApiOptions(..)
) where

import Control.Concurrent
Expand Down Expand Up @@ -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
Expand All @@ -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]

Expand Down
2 changes: 2 additions & 0 deletions docs/source/tools/assistant.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
3 changes: 3 additions & 0 deletions unreleased.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 8ad74da

Please sign in to comment.