simple-cmd-args 0.1.7 → 0.1.8
raw patch · 4 files changed
+126/−8 lines, 4 files
Files
- CHANGELOG.md +4/−0
- README.md +17/−3
- SimpleCmdArgs.hs +102/−1
- simple-cmd-args.cabal +3/−4
CHANGELOG.md view
@@ -2,6 +2,10 @@ `simple-cmd-args` uses [PVP Versioning](https://pvp.haskell.org). +## 0.1.8 (2022-08-03)+- add *LongWith versions of *With and also *LongMods:+ allows defining options with only a long option and no short option+ ## 0.1.7 (2021-06-28) - re-export maybeReader, eitherReader, and ReadM
README.md view
@@ -8,9 +8,13 @@ A thin layer over optparse-applicative that avoids type plumbing for subcommands by using `Parser (IO ())`. +Various wrapper functions are also provided for common option/arg idioms.++See the library's [documentation](https://hackage.haskell.org/package/simple-cmd-args/docs/SimpleCmdArgs.html) for details of all the functions provided.+ ## Usage -```console+```shellsession $ cat readme.hs ``` ```haskell@@ -39,7 +43,7 @@ mkdir parents = if parents then createDirectoryIfMissing True else createDirectory ```-```console+```shellsession $ ghc readme.hs $ ./readme --help readme example@@ -56,6 +60,16 @@ mkdir Create directory $ ./readme echo hello world hello world+$ ./readme mkdir -h+Usage: readme mkdir [-p|--parents] DIR+ Create directory++Available options:+ -p,--parents Make missing directories+ -h,--help Show this help text ``` -See more [examples](https://github.com/juhp/simple-cmd-args/tree/main/examples).+# Examples+See the [examples](https://github.com/juhp/simple-cmd-args/tree/main/examples).++Hackage packages using this library: https://packdeps.haskellers.com/reverse/simple-cmd-args
SimpleCmdArgs.hs view
@@ -1,9 +1,11 @@+{-# LANGUAGE CPP #-}+ {-| This library provides a thin layer on optparse-applicative argument and option parsing, using @Parser (IO ())@, applying commands directly to their argument parsing. -A few option Mod functions are also provided.+Some option Mod functions are also provided. -} module SimpleCmdArgs@@ -16,15 +18,25 @@ -- * Option and arg helpers strArg, switchWith,+ switchLongWith, flagWith, flagWith',+ flagLongWith,+ flagLongWith', switchMods,+ switchLongMods, strOptionWith,+ strOptionLongWith, optionWith,+ optionLongWith, optionMods,+ optionLongMods, strOptionalWith,+ strOptionalLongWith, optionalWith,+ optionalLongWith, optionalMods,+ optionalLongMods, argumentWith, -- * Re-exports from optparse-applicative Parser,@@ -160,6 +172,15 @@ switchWith s l h = switch (switchMods s l h) +-- | switchWith with only long option+--+-- > switchLongWith "option" "help description"+--+-- @since 0.1.8+switchLongWith :: String -> String -> Parser Bool+switchLongWith l h =+ switch (switchLongMods l h)+ -- | flag with Mods -- -- > flagWith offVal onVal 'f' "flag" "help description"@@ -178,6 +199,24 @@ flagWith' val s l h = flag' val (switchMods s l h) +-- | flagWith with only long option+--+-- > flagLongWith offVal onVal "flag" "help description"+--+-- @since 0.1.8+flagLongWith :: a -> a -> String -> String -> Parser a+flagLongWith off on l h =+ flag off on (switchLongMods l h)++-- | flagWith' with only long option+--+-- > flagLongWith' val "flag" "help description"+--+-- @since 0.1.8+flagLongWith' :: a -> String -> String -> Parser a+flagLongWith' val l h =+ flag' val (switchLongMods l h)+ -- | @Mod@s for a switch. -- -- > switchMods 'o' "option" "help description"@@ -186,6 +225,14 @@ switchMods s l h = short s <> long l <> help h +-- | @Mod@s for a switch.+--+-- > switchLongMods "option" "help description"+switchLongMods :: HasName f =>+ String -> String -> Mod f a+switchLongMods l h =+ long l <> help h+ -- | strOption with Mods -- -- > strOptionWith 'o' "option" "METAVAR" "help description"@@ -195,6 +242,15 @@ strOptionWith s l meta h = strOption (optionMods s l meta h) +-- | strOptionWith with only long option+--+-- > strOptionLongWith "option" "METAVAR" "help description"+--+-- @since 0.1.8+strOptionLongWith :: String -> String -> String -> Parser String+strOptionLongWith l meta h =+ strOption (optionLongMods l meta h)+ -- | option with Mods -- -- > optionWith auto 'o' "option" "METAVAR" "help description"@@ -204,6 +260,15 @@ optionWith r s l meta h = option r (optionMods s l meta h) +-- | optionWith with only long option+--+-- > optionLongWith auto "option" "METAVAR" "help description"+--+-- @since 0.1.8+optionLongWith :: ReadM a -> String -> String -> String -> Parser a+optionLongWith r l meta h =+ option r (optionLongMods l meta h)+ -- | @Mod@s for a mandatory option. -- -- > optionMods 'o' "option" "METAVAR" "help description"@@ -212,6 +277,14 @@ optionMods s l meta h = short s <> long l <> metavar meta <> help h +-- | optionMods with only long option+--+-- > optionLongMods "option" "METAVAR" "help description"+optionLongMods :: (HasMetavar f, HasName f) =>+ String -> String -> String -> Mod f a+optionLongMods l meta h =+ long l <> metavar meta <> help h+ -- | strOptional with Mods -- -- > strOptionalWith 'o' "option" "METAVAR" "help description" default@@ -230,6 +303,24 @@ optionalWith r s l meta h d = option r (optionalMods s l meta h d) +-- | strOptionalWith with only long option+--+-- > strOptionalLongWith "option" "METAVAR" "help description" default+--+-- @since 0.1.8+strOptionalLongWith :: String -> String -> String -> String -> Parser String+strOptionalLongWith l meta h d =+ strOption (optionalLongMods l meta (h <> " [default: " <> show d <> "]") d)++-- | optionalWith with only long option+--+-- > optionalLongWith auto "option" "METAVAR" "help description" default+--+-- @since 0.1.8+optionalLongWith :: ReadM a -> String -> String -> String -> a -> Parser a+optionalLongWith r l meta h d =+ option r (optionalLongMods l meta h d)+ -- | @Mod@s for an optional option: includes a default value. -- -- > optionalMods 'o' "option" "METAVAR" "help description" default@@ -237,6 +328,16 @@ Char -> String -> String -> String -> a -> Mod f a optionalMods s l meta h d = short s <> long l <> metavar meta <> help h <> value d++-- | optionalMods with only long option+--+-- > optionalLongMods "option" "METAVAR" "help description" default+--+-- @since 0.1.8+optionalLongMods :: (HasMetavar f, HasName f, HasValue f) =>+ String -> String -> String -> a -> Mod f a+optionalLongMods l meta h d =+ long l <> metavar meta <> help h <> value d -- | argument with METAVAR --
simple-cmd-args.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: simple-cmd-args-version: 0.1.7+version: 0.1.8 synopsis: Simple command args parsing and execution description: This is a small wrapper over optparse-applicative which@@ -13,14 +13,14 @@ license-file: LICENSE author: Jens Petersen maintainer: juhpetersen@gmail.com-copyright: 2019-2021 Jens Petersen+copyright: 2019-2022 Jens Petersen category: System build-type: Simple extra-doc-files: README.md , CHANGELOG.md tested-with: GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.4- GHC == 8.10.4, GHC == 9.0.1+ GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.4 source-repository head type: git@@ -37,4 +37,3 @@ ghc-options: -Wall -fwarn-missing-signatures default-language: Haskell2010- default-extensions: CPP