commander-cli 0.4.0.1 → 0.4.1.1
raw patch · 4 files changed
+20/−31 lines, 4 filesdep +bytestringPVP ok
version bump matches the API change (PVP)
Dependencies added: bytestring
API changes (from Hackage documentation)
+ Options.Commander: instance Options.Commander.Unrender Data.ByteString.Internal.ByteString
+ Options.Commander: instance Options.Commander.Unrender Data.ByteString.Lazy.Internal.ByteString
Files
- README.md +6/−29
- app/Main.hs +2/−0
- commander-cli.cabal +3/−2
- src/Options/Commander.hs +9/−0
README.md view
@@ -1,35 +1,12 @@-# commander-cli+# Commander CLI +[](https://hackage.haskell.org/package/commander-cli) [](https://travis-ci.org/SamuelSchlesinger/commander-cli) -The commander-cli package contains two DSLs for describing command line programs, -one at the type level and one at the term level. The one at the type level looks -like this:--```haskell-type File = "writer" & Arg "file" FilePath & Arg "contents" FilePath & Raw- + "reader" & Arg "file" FilePath & Raw-```--This is a type which encodes information about an command line program we want to write. We can-instantiate a term of this type by writing--```haskell-file :: ProgramT File IO-file = sub (arg $ \file -> arg $ \contents -> raw $ writeFile file contents) - :+: sub (arg $ \file -> raw $ readFile file >>= putStrLn)-```--I can write a term of this type without specifying the File type by using the-TypeApplications extension.--```haskell-file = sub @"writer" (arg @"file" $ \file -> arg @"contents" $ \contents -> raw $ writeFile file contents)- :+: sub @"reader" (arg @"file" $ \file -> raw $ readFile file >>= putStrLn)-```--The library consists of a few basic types which are important for understanding-how to use it. The first thing is the class+This library is meant to allow Haskell programs to quickly and easily construct+command line interfaces which are easy to use, especially as a Haskell user. To+begin, I suggest viewing the task-manager application which comes with this+repository. The library is based around the following classes: ```haskell class Unrender r where
app/Main.hs view
@@ -143,6 +143,7 @@ Nothing -> action c Nothing else putStrLn $ "task " ++ taskName ++ " does not exist." +initializeOrFetch :: IO Context initializeOrFetch = do home <- getHomeDirectory >>= makeAbsolute withCurrentDirectory home $ do@@ -150,4 +151,5 @@ True -> Context home . map (takeWhile (/= '.')) . filter (".task" `isSuffixOf`) <$> listDirectory "tasks" False -> Context home [] <$ createDirectory "tasks" +main :: IO () main = command_ taskManager
commander-cli.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.4 name: commander-cli-version: 0.4.0.1+version: 0.4.1.1 synopsis: A command line argument/option parser library built around a monadic metaphor description: A command line argument/option parser library built around a monadic metaphor. homepage: https://github.com/SamuelSchlesinger/commander-cli@@ -39,7 +39,8 @@ build-depends: base >=4.12 && < 5, mtl >=2.2 && <2.3, text >=1.2 && < 1.3,- unordered-containers >=0.2 && < 0.3+ unordered-containers >=0.2 && < 0.3,+ bytestring >=0.8 && <0.11 hs-source-dirs: src default-language: Haskell2010
src/Options/Commander.hs view
@@ -138,6 +138,9 @@ import Numeric.Natural import System.Environment (getArgs) import Data.Typeable (Typeable, typeRep)+import qualified Data.ByteString as SBS+import qualified Data.ByteString.Char8 as BS8+import qualified Data.ByteString.Lazy as LBS -- | A class for interpreting command line arguments into Haskell types. class Typeable t => Unrender t where@@ -148,6 +151,12 @@ instance Unrender Text where unrender = Just++instance Unrender SBS.ByteString where+ unrender = Just . BS8.pack . unpack++instance Unrender LBS.ByteString where+ unrender = fmap LBS.fromStrict <$> unrender -- | A useful default unrender for small, bounded data types. unrenderSmall :: (Enum a, Bounded a, Show a) => Text -> Maybe a