Enable parsing of usage strings at compile time#7
Merged
ryanartecona merged 3 commits intodocopt:masterfrom Feb 22, 2015
Merged
Enable parsing of usage strings at compile time#7ryanartecona merged 3 commits intodocopt:masterfrom
ryanartecona merged 3 commits intodocopt:masterfrom
Conversation
Member
|
Apologies @smaximov for letting this go completely unacknowledged since you submitted it back in July 😨 ! I was just settling into a new job, and managed to forget to come back to this repo since then. Upon revisiting now, I'm as excited about this PR as I remember being excited about it when I saw it submitted. Thanks especially for putting in the effort! Upon revisiting this old code of mine from when I was just starting out in Haskell, there's...stuff I would like to change. I'm going to try over the next few days to build and play with this locally, and make the API a bit smoother and more consistent. Once that's sorted, I'll make a release with these changes in it. |
4 tasks
ryanartecona
added a commit
that referenced
this pull request
Feb 22, 2015
Enable parsing of usage strings at compile time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.