diff options
Diffstat (limited to 'hsm-core/Hsm/Core/App.hs')
-rw-r--r-- | hsm-core/Hsm/Core/App.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/hsm-core/Hsm/Core/App.hs b/hsm-core/Hsm/Core/App.hs new file mode 100644 index 0000000..88dabb2 --- /dev/null +++ b/hsm-core/Hsm/Core/App.hs @@ -0,0 +1,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 |