summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJensPetersen <>2019-04-08 06:15:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-04-08 06:15:00 (GMT)
commita3653394f9747e0c92590a766cdd46cfeaa0a441 (patch)
treee1e11f4a16eeb244ba4561d41b0bc53dd8e13e2e
parent112cf35dd4bbe0bde15b154bfbd934d43e9fefc0 (diff)
version 0.1.1HEAD0.1.1master
-rw-r--r--CHANGELOG.md5
-rw-r--r--README.md6
-rw-r--r--SimpleCmdArgs.hs59
-rw-r--r--simple-cmd-args.cabal10
4 files changed, 67 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index efae1a4..0ab986f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,11 @@
`simple-cmd-args` uses [PVP Versioning][1].
+## 0.1.1
+- add switchWith, strOptionWith, optionWith, optionalWith,
+ strOptionalWith, argumentWith
+- export simpleCmdArgsWithMods
+
## 0.1.0.1
- fix and improve haddock documentation
diff --git a/README.md b/README.md
index e0e3dfb..2de0372 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
[![Build status](https://secure.travis-ci.org/juhp/simple-cmd-args.svg)](https://travis-ci.org/juhp/simple-cmd-args)
A thin layer over optparse-applicative that avoids type plumbing for
-commands by using `Parser (IO ())`. It also supports with subcommands.
+subcommands by using `Parser (IO ())`.
## Usage
@@ -19,8 +19,8 @@ import SimpleCmd (cmd_)
main =
simpleCmdArgs Nothing "my example tool" "Longer description..." $
subcommands
- [ Subcommand "echo" (putStrLn <$> strArg "NAME") "Print name"
- , Subcommand "ls" (cmd_ "ls" <$> some (strArg "FILE...")) "Touch FILE"
+ [ Subcommand "echo" "Print name" $ putStrLn <$> strArg "NAME"
+ , Subcommand "ls" "Touch FILE" $ cmd_ "ls" <$> some (strArg "FILE...")
]
```
diff --git a/SimpleCmdArgs.hs b/SimpleCmdArgs.hs
index 7dcaa38..6a8c80e 100644
--- a/SimpleCmdArgs.hs
+++ b/SimpleCmdArgs.hs
@@ -9,12 +9,19 @@ A few option Mod functions are also provided.
module SimpleCmdArgs
(simpleCmdArgs,
simpleCmdArgs',
+ simpleCmdArgsWithMods,
Subcommand(..),
subcommands,
strArg,
+ switchWith,
switchMods,
+ strOptionWith,
+ optionWith,
optionMods,
+ strOptionalWith,
+ optionalWith,
optionalMods,
+ argumentWith
)
where
@@ -41,7 +48,7 @@ simpleCmdArgs ::
-- ^ commands
-> IO ()
simpleCmdArgs mversion h pd =
- simpleCmdArgsWithMods mods mversion
+ simpleCmdArgsWithMods mversion mods
where
mods = fullDesc <> header h <> progDesc pd
@@ -59,17 +66,17 @@ simpleCmdArgs'
-- ^ commands
-> IO ()
simpleCmdArgs' mversion h pd =
- simpleCmdArgsWithMods mods mversion
+ simpleCmdArgsWithMods mversion mods
where
mods = fullDesc <> header h <> progDesc pd <> noIntersperse
-- | Generic parser executor with explicit info modifiers
simpleCmdArgsWithMods ::
- InfoMod (IO ()) -- ^ modifiers
- -> Maybe Version -- ^ version string
+ Maybe Version -- ^ version string
+ -> InfoMod (IO ()) -- ^ modifiers
-> Parser (IO ()) -- ^ commands
-> IO ()
-simpleCmdArgsWithMods mods mversion cmdsParser = join $
+simpleCmdArgsWithMods mversion mods cmdsParser = join $
customExecParser (prefs showHelpOnEmpty)
(case mversion of
(Just version) -> info (helper <*> versionOption version <*> cmdsParser) mods
@@ -93,6 +100,13 @@ subcommands = subparser . mconcat . map cmdToParse
strArg :: String -> Parser String
strArg var = strArgument (metavar var)
+-- | switch with Mods
+--
+-- > switchWith 'o' "option" "help description"
+switchWith :: Char -> String -> String -> Parser Bool
+switchWith s l h =
+ switch (switchMods s l h)
+
-- | @Mod@s for a switch.
--
-- > switchMods 'o' "option" "help description"
@@ -101,6 +115,20 @@ switchMods :: HasName f =>
switchMods s l h =
short s <> long l <> help h
+-- | strOption with Mods
+--
+-- > strOptionWith 'o' "option" "METAVAR" "help description"
+strOptionWith :: Char -> String -> String -> String -> Parser String
+strOptionWith s l meta h =
+ strOption (optionMods s l meta h)
+
+-- | option with Mods
+--
+-- > optionWith 'o' "option" "METAVAR" "help description"
+optionWith :: ReadM a -> Char -> String -> String -> String -> Parser a
+optionWith r s l meta h =
+ option r (optionMods s l meta h)
+
-- | @Mod@s for a mandatory option.
--
-- > optionMods 'o' "option" "METAVAR" "help description"
@@ -109,6 +137,20 @@ optionMods :: (HasMetavar f, HasName f) =>
optionMods s l meta h =
short s <> long l <> metavar meta <> help h
+-- | strOptional with Mods
+--
+-- > strOptionalWith 'o' "option" "METAVAR" "help description" default
+strOptionalWith :: Char -> String -> String -> String -> String -> Parser String
+strOptionalWith s l meta h d =
+ strOption (optionalMods s l meta h d)
+
+-- | optional option with Mods, includes a default value.
+--
+-- > optionalWith 'o' "option" "METAVAR" "help description" default
+optionalWith :: ReadM a -> Char -> String -> String -> String -> a -> Parser a
+optionalWith r s l meta h d =
+ option r (optionalMods s l meta h d)
+
-- | @Mod@s for an optional option: includes a default value.
--
-- > optionalMods 'o' "option" "METAVAR" "help description" default
@@ -116,3 +158,10 @@ optionalMods :: (HasMetavar f, HasName f, HasValue f) =>
Char -> String -> String -> String -> a -> Mod f a
optionalMods s l meta h d =
short s <> long l <> metavar meta <> help h <> value d
+
+-- | argument with METAVAR
+--
+-- > argumentWith auto "METAVAR"
+argumentWith :: ReadM a -> String -> Parser a
+argumentWith r meta =
+ argument r (metavar meta)
diff --git a/simple-cmd-args.cabal b/simple-cmd-args.cabal
index 052c9ad..ae2665a 100644
--- a/simple-cmd-args.cabal
+++ b/simple-cmd-args.cabal
@@ -1,12 +1,12 @@
cabal-version: 1.18
name: simple-cmd-args
-version: 0.1.0.1
+version: 0.1.1
synopsis: Simple command args parsing and execution
description:
This is a small wrapper over optparse-applicative which
- allows combining args parsers directly with IO commands,
- avoiding command type boilerplate. It supports subcommands
- and also provides a few option Mod functions.
+ allows combining args parsers directly with IO commands.
+ For subcommands this can avoid type boilerplate.
+ It also provides a few functions for common Mod combinations.
homepage: https://github.com/juhp/simple-cmd-args
bug-reports: https://github.com/juhp/simple-cmd-args/issues
license: BSD3
@@ -19,7 +19,7 @@ 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.3
+ GHC == 8.4.4, GHC == 8.6.4
source-repository head
type: git