commander-cli 0.7.0.0 → 0.8.0.0
raw patch · 3 files changed
+24/−20 lines, 3 filesdep +commandertPVP ok
version bump matches the API change (PVP)
Dependencies added: commandert
API changes (from Hackage documentation)
+ Options.Commander: data family ProgramT p (m :: * -> *) a;
+ Options.Commander: }
- Options.Commander: class HasProgram p
+ Options.Commander: class HasProgram p where {
Files
- commander-cli.cabal +12/−4
- src/Control/Monad/Commander.hs +1/−2
- src/Options/Commander.hs +11/−14
commander-cli.cabal view
@@ -1,9 +1,9 @@ cabal-version: 2.4 name: commander-cli-version: 0.7.0.0-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.+version: 0.8.0.0+synopsis: A command line argument/option parser library+description: A command line argument/option parser library. homepage: https://github.com/SamuelSchlesinger/commander-cli bug-reports: https://github.com/SamuelSchlesinger/commander-cli/issues license: MIT@@ -13,7 +13,12 @@ copyright: 2019 Samuel Schlesinger category: System, CLI, Options, Parsing extra-source-files: CHANGELOG.md, README.md+tested-with: GHC ==8.6.3 || ==8.8.3 || ==8.10.1 +source-repository head+ type: git + location: https://github.com/samuelschlesinger/commander-cli+ library exposed-modules: Options.Commander, Control.Monad.Commander other-extensions: ViewPatterns,@@ -40,7 +45,8 @@ bytestring >=0.8 && <1, mtl >=2.2 && <3, text >=1.2 && <2,- unordered-containers >=0.2 && < 1+ unordered-containers >=0.2 && < 1,+ commandert >=0.1 hs-source-dirs: src default-language: Haskell2010 @@ -60,6 +66,7 @@ text >=1.2 && < 2, directory >= 1.3 && < 2, process >= 1.6 && < 2,+ commandert >=0.1, commander-cli hs-source-dirs: app default-language: Haskell2010@@ -70,5 +77,6 @@ build-depends: base >= 4.12 && < 5, text >=1.2 && < 2, unordered-containers >= 0.2 && < 1,+ commandert >=0.1, commander-cli default-language: Haskell2010
src/Control/Monad/Commander.hs view
@@ -43,8 +43,7 @@ -> m (Maybe a) runCommanderT (Action action) state = do (action', state') <- action state- m <- runCommanderT action' state'- return m+ runCommanderT action' state' runCommanderT Defeat _ = return Nothing runCommanderT (Victory a) _ = return (Just a)
src/Options/Commander.hs view
@@ -2,15 +2,12 @@ {-# LANGUAGE BlockArguments #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE DerivingVia #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeApplications #-}@@ -99,7 +96,7 @@ syntax for CLI programs using the 'ProgramT' data family, and defining the interpretation of all of the various pieces of a CLI. -}- HasProgram(run, hoist, invocations),+ HasProgram(ProgramT, run, hoist, invocations), ProgramT(ArgProgramT, unArgProgramT, OptProgramT, unOptProgramT, unOptDefault, RawProgramT, unRawProgramT,@@ -128,9 +125,9 @@ import Control.Applicative (Alternative(..)) import Control.Arrow (first)-import Control.Monad ((<=<))-import Control.Monad (ap, void)+import Control.Monad (ap, void, (<=<)) import Control.Monad.Trans (MonadIO(..), MonadTrans(..))+import Data.Functor (($>)) import Data.HashMap.Strict as HashMap import Data.HashSet as HashSet import Data.Int@@ -358,9 +355,9 @@ Nothing -> return (run (unOptProgramT f (unOptDefault f)), State{..}) hoist n (OptProgramT f d) = OptProgramT (hoist n . f) d invocations =- [(("-" <> (pack $ symbolVal (Proxy @option)) - <> " <" <> (pack $ symbolVal (Proxy @name)) - <> " :: " <> (pack $ show (typeRep (Proxy @t)))+ [(("-" <> pack (symbolVal (Proxy @option)) + <> " <" <> pack (symbolVal (Proxy @name)) + <> " :: " <> pack (show (typeRep (Proxy @t))) <> "> ") <>) ] <*> invocations @p instance (KnownSymbol flag, HasProgram p) => HasProgram (Flag flag & p) where@@ -369,7 +366,7 @@ let presence = HashSet.member (pack (symbolVal (Proxy @flag))) flags return (run (unFlagProgramT f presence), State{..}) hoist n = FlagProgramT . fmap (hoist n) . unFlagProgramT- invocations = [(("~" <> (pack $ symbolVal (Proxy @flag)) <> " ") <>)] <*> invocations @p+ invocations = [(("~" <> pack (symbolVal (Proxy @flag)) <> " ") <>)] <*> invocations @p instance (KnownSymbol name, HasProgram p) => HasProgram (Named name & p) where newtype ProgramT (Named name &p) m a = NamedProgramT { unNamedProgramT :: ProgramT p m a }@@ -387,7 +384,7 @@ else return (Defeat, State{..}) [] -> return (Defeat, State{..}) hoist n = SubProgramT . hoist n . unSubProgramT- invocations = [((pack $ symbolVal (Proxy @sub) <> " ") <> )] + invocations = [(pack (symbolVal (Proxy @sub) <> " ") <> )] <*> invocations @p -- | A simple default for getting out the arguments, options, and flags@@ -534,7 +531,7 @@ Action a -> Action $ \state -> do (commander', state') <- a state pure (withDefeatEffects ma commander', state')- Defeat -> Action $ \state -> ma *> pure (Defeat, state)+ Defeat -> Action $ \state -> ma $> (Defeat, state) Victory a -> Victory a -- | Middleware to have effects whenever the program successfully computes@@ -545,14 +542,14 @@ (commander', state') <- a state pure (withVictoryEffects ma commander', state') Defeat -> Defeat- Victory a -> Action $ \state -> ma *> pure (Victory a, state)+ Victory a -> Action $ \state -> ma $> (Victory a, state) -- | Middleware to log the state to standard out for every step of the -- 'CommanderT' computation. logState :: MonadIO m => Middleware m m logState commander = case commander of- Action a -> do+ Action a -> Action $ \state -> do liftIO $ print state fmap (first logState) (a state)