hydrogen-cli-args 0.9 → 0.10
raw patch · 3 files changed
+52/−6 lines, 3 filesdep ~hydrogen-preludePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: hydrogen-prelude
API changes (from Hackage documentation)
+ Hydrogen.CliArgs: type OptArgs = (MultiMap String String, Set String, [String])
- Hydrogen.CliArgs: getOpts :: [Option] -> IO (MultiMap String String, Set String, [String])
+ Hydrogen.CliArgs: getOpts :: [Option] -> IO OptArgs
- Hydrogen.CliArgs: getOpts' :: [Option] -> [String] -> (MultiMap String String, Set String, [String])
+ Hydrogen.CliArgs: getOpts' :: [Option] -> [String] -> OptArgs
Files
- README.md +45/−2
- hydrogen-cli-args.cabal +2/−2
- src/Hydrogen/CliArgs.hs +5/−2
README.md view
@@ -40,13 +40,56 @@ Long options can be given as `--key value` or as `--key=value`. -Short options can be given as `-D value` as well as `--Dvalue`.+Short options can be given as `-D value` as well as `-Dvalue`. If a switch, defined by `switch` is given, it will show up in the `switches` `Set`. You can query for whether a switch is set or not with `(?)`. -Switches can be comined, i.e. `-hv` is the same as `-h -v`.+Switches can be combined, i.e. `-hv` is the same as `-h -v`. If `--` is supplied as an argument, no options are evaluated beyond this point. Any unknown or malformed option (`-x`, `--xxxx`) will be treated as an argument. ++API+---++### Define options++#### `switch :: String -> Option`++Defines a command line switch with the given long name.+++#### `optarg :: String -> Option`++Defines a command line option with the given long name.+++#### `alias ~: option :: Char -> Option -> Option`++Defines a shorthand for the given option.+++#### `option ~? check :: Option -> (String -> Bool) -> Option`++Defines a check which the optional arguments' value has to pass.+++#### `option ~= pattern :: Option -> String -> Option`++Defines a pattern which the optional arguments' value must match.+++### Get options and arguments++#### `type OptArgs = (MultiMap String String, Set String, [String])`++#### `getOpts :: [Options] -> IO OptArgs`++#### `getOpts' :: [Options] -> [String] -> OptArgs`+++### Query MultiMaps / Sets++Part of [hydrogen-prelude](http://github.com/scravy/hydrogen-prelude).
hydrogen-cli-args.cabal view
@@ -1,5 +1,5 @@ name: hydrogen-cli-args-version: 0.9+version: 0.10 homepage: https://scravy.de/hydrogen-cli-args/ synopsis: Hydrogen Command Line Arguments Parser license: MIT@@ -20,7 +20,7 @@ build-depends: base ==4.7.* , containers ==0.5.* , hydrogen-multimap ==0.1- , hydrogen-prelude ==0.9+ , hydrogen-prelude ==0.10 hs-source-dirs: src ghc-options: -Wall default-language: Haskell2010
src/Hydrogen/CliArgs.hs view
@@ -11,6 +11,7 @@ , Has (..) , MultiMap , Container (..)+ , OptArgs ) where import Hydrogen.Prelude.System@@ -18,6 +19,8 @@ import qualified Data.Map as Map import qualified Data.Set as Set +type OptArgs = (MultiMap String String, Set String, [String])+ switch, optarg :: String -> Option switch = OptSwitch@@ -69,10 +72,10 @@ OptShort _ xs -> check xs OptCheck x _ -> Just x -getOpts :: [Option] -> IO (MultiMap String String, Set String, [String])+getOpts :: [Option] -> IO OptArgs getOpts opts = getOpts' opts <$> getArgs -getOpts' :: [Option] -> [String] -> (MultiMap String String, Set String, [String])+getOpts' :: [Option] -> [String] -> OptArgs getOpts' opts = readArgs MultiMap.empty Set.empty where