Make arion repl work

This commit is contained in:
Robert Hensing 2019-09-27 21:45:06 +02:00
parent b9488b7f49
commit fcf270c80c
3 changed files with 38 additions and 6 deletions

View file

@ -70,9 +70,9 @@ textArgument = fmap T.pack . strArgument
parseCommand :: Parser (CommonOptions -> IO ())
parseCommand =
hsubparser
( command "cat" (info (pure runCat) (progDesc "TODO: cat doc" <> fullDesc))
<> command "repl" (info (pure runRepl) (progDesc "TODO: repl doc" <> fullDesc))
<> command "exec" (info (pure runExec) (progDesc "TODO: exec doc" <> fullDesc))
( command "cat" (info (pure runCat) (progDesc "Spit out the docker compose file as JSON" <> fullDesc))
<> command "repl" (info (pure runRepl) (progDesc "Start a nix repl for the whole composition" <> fullDesc))
-- <> command "exec" (info (pure runExec) (progDesc "TODO: exec doc" <> fullDesc))
)
<|>
hsubparser
@ -172,8 +172,18 @@ runCat co = do
T.hPutStrLn stdout (pretty v)
runRepl :: CommonOptions -> IO ()
runRepl opts =
T.putStrLn "Running repl ... TODO"
runRepl co = do
putErrText
"Launching a repl for you. To get started:\n\
\\n\
\To see deployment-wide configuration\n\
\ type config. and hit TAB\n\
\To see the services\n\
\ type config.docker-compose.evaluatedServices TAB or ENTER\n\
\To bring the top-level Nixpkgs attributes into scope\n\
\ type :a (config._module.args.pkgs) // { inherit config; }\n\
\"
Arion.Nix.replForComposition =<< defaultEvaluationArgs co
runExec :: CommonOptions -> IO ()
runExec opts =

View file

@ -40,7 +40,6 @@ run args = do
withCreateProcess procSpec $ \_in _out _err procHandle -> do
-- Wait for process exit and 'err' printout
exitCode <- waitForProcess procHandle
case exitCode of

View file

@ -2,7 +2,9 @@
module Arion.Nix
( evaluateComposition
, withEvaluatedComposition
, buildComposition
, withBuiltComposition
, replForComposition
, EvaluationArgs(..)
, EvaluationMode(..)
) where
@ -137,6 +139,27 @@ withBuiltComposition ea f = do
buildComposition path ea
f path
replForComposition :: EvaluationArgs -> IO ()
replForComposition ea = do
evalComposition <- getEvalCompositionFile
let args =
[ "repl", evalComposition ]
++ argArgs ea
++ map toS (evalUserArgs ea)
procSpec = (proc "nix" args) { cwd = evalWorkDir ea }
withCreateProcess procSpec $ \_in _out _err procHandle -> do
exitCode <- waitForProcess procHandle
case exitCode of
ExitSuccess -> pass
ExitFailure 1 -> exitFailure
e@ExitFailure {} -> do
throwIO $ FatalError $ "nix repl failed with " <> show exitCode
exitWith e
argArgs :: EvaluationArgs -> [[Char]]
argArgs ea =
[ "--argstr"