Skip to content

Commit

Permalink
Not required all
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisbcc authored and sestrella committed Jul 11, 2024
1 parent d5356d3 commit de1c423
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/System/Hapistrano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -289,24 +289,21 @@ initConfig getLine' = do
putStrLn $ "Configuration written at " <> configFilePath

where
prompt :: Show a => String -> a -> MParser a -> Bool -> IO a
prompt parameterName def parser isRequired = do
prompt :: Show a => String -> a -> MParser a -> IO a
prompt parameterName def parser = do
userInput <- prompt' (parameterName <> " (default: " <> show def <> ")")
if null userInput && isRequired then do
hPutStrLn stderr ("Required value: " <> parameterName)
prompt parameterName def parser isRequired
else if null userInput && not isRequired then
if null userInput then
pure def
else do
let parsed = M.parse (parser <* M.eof) "" userInput
case parsed of
Left err -> do
hPutStrLn stderr (M.errorBundlePretty err)
prompt parameterName def parser isRequired
prompt parameterName def parser
Right res -> pure res

promptYN = do
userInput <- prompt "Include restart command? y/N" 'N' yNParser False
userInput <- prompt "Include restart command? y/N" 'N' yNParser
case toLower userInput of
'y' -> pure $ Just "echo 'Restart command'"
_ -> pure Nothing
Expand All @@ -320,10 +317,10 @@ initConfig getLine' = do
generateUserConfig initCfg = do
InitTemplateConfig{..} <- initCfg
InitTemplateConfig
<$> prompt "repo" repo pUri True
<*> prompt "revision" revision stringParser False
<*> prompt "host" host stringParser False
<*> prompt "port" port numberParser False
<$> prompt "repo" repo pUri
<*> prompt "revision" revision stringParser
<*> prompt "host" host stringParser
<*> prompt "port" port numberParser
<*> pure buildScript
<*> promptYN

Expand Down

0 comments on commit de1c423

Please sign in to comment.