aboutsummaryrefslogtreecommitdiff
path: root/hsm-core/Hsm/Core/App.hs
blob: 88dabb29819a196b79cb8500ac204493ba76c125 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- Provides combinators for bootstrapping applications with:
-- - Automated command-line parsing
-- - Help text generation
module Hsm.Core.App
  ( bootstrapApp
  , bootstrapAppNoEcho
  )
where

import Data.Composition ((.:.))
import Options.Applicative (Parser, execParser, fullDesc, helper, info, progDesc, (<**>))
import System.IO.Echo (withoutInputEcho)

-- Launches a console application with input echo enabled
bootstrapApp :: Parser o -> String -> (o -> IO a) -> IO a
bootstrapApp parser desc app = execParser (info (parser <**> helper) $ fullDesc <> progDesc desc) >>= app

-- Launches an application with hidden input echo
bootstrapAppNoEcho :: Parser o -> String -> (o -> IO a) -> IO a
bootstrapAppNoEcho = withoutInputEcho .:. bootstrapApp