packages feed

optparse-helper (empty) → 0.1.0.0

raw patch · 5 files changed

+218/−0 lines, 5 filesdep +basedep +optparse-applicativesetup-changed

Dependencies added: base, optparse-applicative

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2016, Peter Harpending++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Peter Harpending nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,14 @@+# optparse-helper++Haskell library for helper helper functions for+optparse-applicative. See the+[Haddock documentation](http://hackage.haskell.org/package/optparse-helper)+for usage info.++## Contact++Bugs, questions, comments, and complaints should be brought up in the+[GitHub bug tracker](https://github.com/pharpend/optparse-helper/issues). If+you don't want to use that for whatever reason, you can email me at+`peter@harpending.org`. I also am on IRC occasionally, under the nick+`pharpend` on FreeNode.net.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ optparse-helper.cabal view
@@ -0,0 +1,46 @@+name:                optparse-helper+version:             0.1.0.0+synopsis:            Helper functions for optparse-applicative.+description:+  The optparse-applicative package, as well as optparse-simple, has some+  undesirable behavior by default, and is quite verbose. This package exists to+  work around those two.+  .+  For instance:+  .+  * optparse-applicative does not show help on error by default.+  .+  * optparse-applicative does not disambiguate commands. So, if you have a+    command @my-executable foobar@, but your user runs @my-executable f@,+    optparse-applicative will not disambiguate this by default.+  .+  For more specific documentation, see the module documentation for+  "Options.Applicative.Helper".+homepage:            https://github.com/pharpend/optparse-helper+bug-reports:         https://github.com/pharpend/optparse-helper/issues+license:             BSD3+license-file:        LICENSE+author:              Peter Harpending+maintainer:          peter@harpending.org+copyright:           Copyright (c) 2016, Peter Harpending+category:            System+build-type:          Simple+cabal-version:       >=1.10+extra-source-files:+  LICENSE+  README.md++library+  hs-source-dirs:      src+  default-language:    Haskell2010+  default-extensions:+    LambdaCase+  build-depends:+      base ==4.8.*+    , optparse-applicative+  exposed-modules:+    Options.Applicative.Helper++source-repository head+  type:     git+  location: https://github.com/pharpend/optparse-helper.git
+ src/Options/Applicative/Helper.hs view
@@ -0,0 +1,126 @@+-- |Helper functions to complement "Options.Applicative"+-- +-- To use, do something like this:+-- +-- > module Main where+-- >+-- > import Options.Applicative+-- > import Options.Applicative.Helper+-- > +-- > data ParserResult = Result1+-- >                   | Result2+-- >                   | Result3+-- >   deriving (Show)+-- >+-- > main :: IO ()+-- > main =+-- >   do myResult <- helperExecParser myParser (fpDesc "Demonstration")+-- >      doSomethingWith myResult+-- >+-- > myParser :: Parser ParserResult+-- > myParser =+-- >   subconcat [ command "result1"+-- >                       (infoHelper (pure Result1)+-- >                                   (fpDesc "Result1"))+-- >             , command "result2"+-- >                       (infoHelper (pure Result2)+-- >                                   (fpDesc "Result2"))+-- >             , command "result3"+-- >                       (infoHelper (pure Result3)+-- >                                   (fpDesc "Result3"))+-- >             ]+-- >+-- > doSomethingWith :: ParserResult -> IO ()+-- > doSomethingWith = print+module Options.Applicative.Helper where++import Options.Applicative++-- |Wrapper around 'info' and 'helper'+-- +-- > info (helper <*> a) ...+--+-- Instead, it's just+--+-- > infoHelper a ...+infoHelper :: Parser a -> InfoMod a -> ParserInfo a+infoHelper a = info (helper <*> a)++-- |Sort of like 'mconcat' for 'Alternative's+-- +-- Instead of +-- +-- > foo <|> bar <|> baz <|> quux <|> ...+-- +-- Now, it's just+-- +-- > altconcat [ foo+-- >           , bar+-- >           , baz+-- >           , quux+-- >           ...+-- >           ]+altconcat :: Alternative f => [f a] -> f a+altconcat =+  \case+    [] -> empty+    x : xs -> x <|> altconcat xs++-- |> altconcat . fmap subparser+-- +-- Instead of+-- +-- > subparser (command "foo" ...)+-- >   <|> subparser (command "bar" ...)+-- >   <|> subparser (command "baz" ...)+-- >   ...+-- +-- Instead it's+-- +-- > subconcat [ command "foo" ...+-- >           , command "bar" ...+-- >           , command "baz" ...+-- >           ...+-- >           ]+subconcat :: [Mod CommandFields a] -> Parser a+subconcat = altconcat . fmap subparser++-- |> mappend fullDesc . progDesc+-- +-- > mconcat [ fullDesc+-- >         , progDesc "whatever"+-- >         ...+-- >         ]+-- +-- Now, it's just+-- +-- > mconcat [ fpDesc "whatever"+-- >         ...+-- >         ]+fpDesc :: String -> InfoMod a+fpDesc = mappend fullDesc . progDesc++-- |Preferences that I like. Using these preferences, your app will +-- +-- * disambiguate shortened subcommands+-- * show help whenever someone makes an error.+-- +-- Note that you should use this in combination with 'infoHelper' for+-- maximum helpfulness.+--+-- > prefs helperPrefsMod+helperPrefs :: ParserPrefs+helperPrefs = prefs helperPrefsMod++-- |The 'PrefsMod' for 'helperPrefs' so that you can add on your own+-- preferences.+-- +-- > mappend disambiguate showHelpOnError+helperPrefsMod :: ParserPrefs+helperPrefsMod = mappend disambiguate showHelpOnError++-- |Wrapper around 'customExecParser', 'helperPrefs', and 'infoHelper'+-- +-- > helperExecParser a b = customExecParser helperPrefs (infoHelper a b)+helperExecParser :: Parser a -> InfoMod a -> IO ()+helperExecParser a b = customExecParser helperPrefs (infoHelper a b)