Enable parsing of usage strings at compile time #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull requests introduces the module
System.Console.Docopt.QQwhich exports twoQuasiQuoters:docoptanddocoptFile.docoptparses a literal string — usage string — into some abstract data type (a wrapper aroundOptFormat);docoptFiletakes a file and parses its contents. Parsing is done at the compile time, which means an invalid usage string will result in a compile time error.Example from Readme:
{-# LANGUAGE QuasiQuotes #-} module Main where import Control.Monad (when) import Data.Char (toUpper) import System.Console.Docopt.QQ patterns :: Docopt patterns = [docopt| Usage: myprog cat <file> myprog echo [--caps] <string> Options: -c, --caps Caps-lock the echoed argument |] main :: IO () main = do args <- parseArgs' patterns when (args `isPresent` (command "cat")) $ do file <- args `getArg` (argument "file") putStr =<< readFile file when (args `isPresent` (command "echo")) $ do let charTransform = if args `isPresent` (longOption "caps") then toUpper else id string <- args `getArg` (argument "string") putStrLn $ map charTransform stringSee docs for
System.Console.Docopt.QQfor more info.