packages feed

simple-cmd-args 0.1.5 → 0.1.6

raw patch · 4 files changed

+52/−10 lines, 4 files

Files

CHANGELOG.md view
@@ -2,6 +2,10 @@  `simple-cmd-args` uses [PVP Versioning](https://pvp.haskell.org). +## 0.1.6 (2020-03-25)+- subcommands now have --help option+- output a warning if there are duplicate commands+ ## 0.1.5 (2020-02-06) - add Eq and Ord instances for Subcommand 
README.md view
@@ -14,14 +14,28 @@ ```haskell import SimpleCmdArgs import Control.Applicative (some)-import SimpleCmd (cmd_)+import System.Directory  main =-  simpleCmdArgs Nothing "my example tool" "Longer description..." $+  simpleCmdArgs Nothing "example-tool" "Longer description..." $   subcommands-    [ Subcommand "echo" "Print name" $ putStrLn <$> strArg "NAME"-    , Subcommand "ls" "Touch FILE" $ cmd_ "ls" <$> some (strArg "FILE...")+    [ Subcommand "echo" "Print words" $+      putStrLn . unwords <$> some (strArg "STR...")+    , Subcommand "ls" "List directory" $+      ls <$> strArg "DIR"+    , Subcommand "mkdir" "Create directory" $+      mkdir <$> parentsOpt <*> strArg "DIR"     ]+  where+    parentsOpt = switchWith 'p' "parents" "Make missing directories"++ls :: FilePath -> IO ()+ls dir =+  listDirectory dir >>= mapM_ putStrLn++mkdir :: Bool -> FilePath -> IO ()+mkdir parents =+  if parents then createDirectoryIfMissing True else createDirectory ```  See more [examples](https://github.com/juhp/simple-cmd-args/tree/master/examples).
SimpleCmdArgs.hs view
@@ -10,8 +10,10 @@   (simpleCmdArgs,    simpleCmdArgs',    simpleCmdArgsWithMods,+   -- * Subcommands    Subcommand(..),    subcommands,+   -- * Option and arg helpers    strArg,    switchWith,    flagWith,@@ -24,6 +26,7 @@    optionalWith,    optionalMods,    argumentWith,+   -- * Re-exports from optparse-applicative    Parser,    auto,    many,@@ -38,19 +41,27 @@   ) where +#if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,13,0))+#else import Control.Applicative ((<|>), #if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,8,0)) #else                             (<$>), (<*>) #endif                            )+#endif import Control.Monad (join)+import Data.List (nub) #if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,8,0)) #else import Data.Monoid (mconcat) #endif+#if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,13,0))+#else import Data.Semigroup ((<>))+#endif import Data.Version+import Debug.Trace (trace) import Options.Applicative  -- | Parser executor (allows interspersed args and options)@@ -110,20 +121,33 @@ data Subcommand =   Subcommand String String (Parser (IO ())) +subCmdName :: Subcommand -> String+subCmdName (Subcommand n _ _) = n++-- | equality by command name+-- -- @since 0.1.5 instance Eq Subcommand where-  (Subcommand n1 _ _) == (Subcommand n2 _ _) = n1 == n2+  c1 == c2 = subCmdName c1 == subCmdName c2 +-- | comparison by command name+-- -- @since 0.1.5 instance Ord Subcommand where-  compare (Subcommand n1 _ _) (Subcommand n2 _ _) = compare n1 n2+  compare c1 c2 = compare (subCmdName c1) (subCmdName c2) --- | list of @Subcommand@ that can be run by @simpleCmdArgs@+-- | Create a list of @Subcommand@ that can be run by @simpleCmdArgs@ subcommands :: [Subcommand] -> Parser (IO ())-subcommands = subparser . mconcat . map cmdToParse+subcommands = hsubparser . mconcat . map cmdToParse . warnIfDuplicates   where     cmdToParse (Subcommand name cmddesc cmdparse) =       command name (info cmdparse (progDesc cmddesc))++    warnIfDuplicates :: [Subcommand] -> [Subcommand]+    warnIfDuplicates subcmds =+      if dups then trace "duplicate subcommand found" subcmds else subcmds+      where+        dups = nub subcmds /= subcmds  -- | A string arg parser with a METAVAR for help strArg :: String -> Parser String
simple-cmd-args.cabal view
@@ -1,6 +1,6 @@ cabal-version:       1.18 name:                simple-cmd-args-version:             0.1.5+version:             0.1.6 synopsis:            Simple command args parsing and execution description:             This is a small wrapper over optparse-applicative which@@ -20,7 +20,7 @@                    , CHANGELOG.md tested-with:         GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4,                      GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2,-                     GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.2+                     GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.3  source-repository head   type:                git