core-program 0.2.7.1 → 0.2.9.1
raw patch · 6 files changed
+77/−49 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Core.Program.Arguments: blank :: Config
- Core.Program.Arguments: complex :: [Commands] -> Config
- Core.Program.Arguments: simple :: [Options] -> Config
- Core.Program.Execute: sleep :: Rational -> Program τ ()
+ Core.Program.Arguments: blankConfig :: Config
+ Core.Program.Arguments: complexConfig :: [Commands] -> Config
+ Core.Program.Arguments: simpleConfig :: [Options] -> Config
+ Core.Program.Execute: lookupEnvironmentValue :: LongName -> Parameters -> Maybe String
+ Core.Program.Execute: sleepThread :: Rational -> Program τ ()
Files
- LICENSE +16/−29
- core-program.cabal +6/−5
- lib/Core/Program/Arguments.hs +22/−7
- lib/Core/Program/Context.hs +10/−3
- lib/Core/Program/Execute.hs +22/−4
- lib/Core/Program/Notify.hs +1/−1
LICENSE view
@@ -1,32 +1,19 @@-Opinionated Haskell Interoperability--Copyright © 2018-2019 Athae Eredh Siniath and Others-All rights reserved.--Redistribution and use in source and binary forms, with or without-modification, are permitted provided that the following conditions-are met:+Copyright © 2018-2021 Athae Eredh Siniath and Others - 1. Redistributions of source code must retain the above copyright- notice, this list of conditions and the following disclaimer.+Permission is hereby granted, free of charge, to any person obtaining a+copy of this software and associated documentation files (the "Software"),+to deal in the Software without restriction, including without limitation+the rights to use, copy, modify, merge, publish, distribute, sublicense,+and/or sell copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following conditions: - 2. Redistributions in binary form must reproduce the above- copyright notice, this list of conditions and the following- disclaimer in the documentation and/or other materials provided- with the distribution.- - 3. Neither the name of the project nor the names of its contributors- may be used to endorse or promote products derived from this - software without specific prior written permission.+The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER+DEALINGS IN THE SOFTWARE.
core-program.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack ----- hash: 9e2322161bd290450527b4d25e2a413be161d20fb7ec735599c5f87f3cc62cd5+-- hash: 7ef8b1887a1354fbfa0d647d220186bf240e0cacd7b36d144b0682efac37a8cd name: core-program-version: 0.2.7.1+version: 0.2.9.1 synopsis: Opinionated Haskell Interoperability description: A library to help build command-line programs, both tools and longer-running daemons.@@ -25,9 +25,10 @@ author: Andrew Cowie <istathar@gmail.com> maintainer: Andrew Cowie <istathar@gmail.com> copyright: © 2018-2021 Athae Eredh Siniath and Others-license: BSD3+license: MIT license-file: LICENSE-tested-with: GHC == 8.10.4+tested-with:+ GHC == 8.10.6 build-type: Simple source-repository head
lib/Core/Program/Arguments.hs view
@@ -21,9 +21,9 @@ module Core.Program.Arguments ( -- * Setup Config,- blank,- simple,- complex,+ blankConfig,+ simpleConfig,+ complexConfig, baselineOptions, Parameters (..), ParameterValue (..),@@ -43,6 +43,9 @@ InvalidCommandLine (..), buildUsage, buildVersion,+ blank,+ simple,+ complex, ) where import Data.Hashable (Hashable)@@ -127,8 +130,12 @@ options. Your program won't process any command-line options or arguments, which would be weird in most cases. Prefer 'simple'. -}+blankConfig :: Config+blankConfig = Blank+ blank :: Config-blank = Blank+blank = blankConfig+{-# DEPRECATED blank "use blankConfig instead" #-} {- | Declare a simple (as in normal) configuration for a program with any number@@ -137,7 +144,7 @@ @ main :: 'IO' () main = do- context <- 'Core.Program.Execute.configure' \"1.0\" 'Core.Program.Execute.None' ('simple'+ context <- 'Core.Program.Execute.configure' \"1.0\" 'Core.Program.Execute.None' ('simpleConfig' [ 'Option' "host" ('Just' \'h\') 'Empty' ['quote'| Specify an alternate host to connect to when performing the frobnication. The default is \"localhost\".@@ -191,8 +198,12 @@ For information on how to use the multi-line string literals shown here, see 'quote' in "Core.Text.Utilities". -}+simpleConfig :: [Options] -> Config+simpleConfig options = Simple (options ++ baselineOptions)+ simple :: [Options] -> Config-simple options = Simple (options ++ baselineOptions)+simple = simpleConfig+{-# DEPRECATED simple "Use simpleConfig instead" #-} {- | Declare a complex configuration (implying a larger tool with various@@ -275,8 +286,12 @@ For information on how to use the multi-line string literals shown here, see 'quote' in "Core.Text.Utilities". -}+complexConfig :: [Commands] -> Config+complexConfig commands = Complex (commands ++ [Global baselineOptions])+ complex :: [Commands] -> Config-complex commands = Complex (commands ++ [Global baselineOptions])+complex = complexConfig+{-# DEPRECATED complex "Use complexConfig instead" #-} {- | Description of the command-line structure of a program which has
lib/Core/Program/Context.hs view
@@ -174,9 +174,16 @@ One of the quirks of Haskell is that it is difficult to refer to code in the Main module when you've got a number of programs kicking around in a project-each with a @main@ function. So you're best off putting your top-level-'Program' actions in a separate modules so you can refer to them from test-suites and example snippets.+each with a @main@ function. One way of dealing with this is to put your+top-level 'Program' actions in a separate modules so you can refer to them+from test suites and example snippets.++/Interoperating with the rest of the Haskell ecosystem/++The 'Program' monad is a wrapper over 'IO'; at any point when you need to move+to another package's entry point, just use 'liftIO'. It's re-exported by+"Core.System.Base" for your convenience. Later, you might be interested in+unlifting back to Program; see "Core.Program.Unlift". -} newtype Program τ α = Program (ReaderT (Context τ) IO α) deriving (Functor, Applicative, Monad, MonadIO, MonadReader (Context τ))
lib/Core/Program/Execute.hs view
@@ -64,6 +64,7 @@ lookupOptionFlag, lookupOptionValue, lookupArgument,+ lookupEnvironmentValue, getProgramName, setProgramName, getVerbosityLevel,@@ -80,6 +81,7 @@ Thread, forkThread, fork,+ sleepThread, sleep, resetTimer, waitThread,@@ -206,7 +208,7 @@ -} execute :: Program None α -> IO () execute program = do- context <- configure "" None (simple [])+ context <- configure "" None (simpleConfig []) executeWith context program {- |@@ -526,7 +528,7 @@ example, to delay a second and a half, do: @- 'sleep' 1.5+ 'sleepThread' 1.5 @ (this wraps __base__'s 'threadDelay')@@ -535,11 +537,15 @@ -- -- FIXME is this the right type, given we want to avoid type default warnings? ---sleep :: Rational -> Program τ ()-sleep seconds =+sleepThread :: Rational -> Program τ ()+sleepThread seconds = let us = floor (toRational (seconds * 1e6)) in liftIO $ threadDelay us +sleep :: Rational -> Program τ ()+sleep = sleepThread+{-# DEPRECATED sleep "Use sleepThread instead" #-}+ {- | Wait for the completion of a thread, returning the result. This is a blocking operation.@@ -649,6 +655,18 @@ Nothing -> Nothing Just argument -> case argument of _ -> Just True -- nom, nom++{- |+Look to see if the user supplied the named environment variable and if so,+return what its value was.+-}+lookupEnvironmentValue :: LongName -> Parameters -> Maybe String+lookupEnvironmentValue name params =+ case lookupKeyValue name (environmentValuesFrom params) of+ Nothing -> Nothing+ Just param -> case param of+ Empty -> Nothing+ Value str -> Just str {- | Illegal internal state resulting from what should be unreachable code or
lib/Core/Program/Notify.hs view
@@ -86,4 +86,4 @@ sequence_ stoppers return () - sleep 0.1+ sleepThread 0.1