microlens-process (empty) → 0.0.1.0
raw patch · 7 files changed
+304/−0 lines, 7 filesdep +basedep +filepathdep +microlenssetup-changed
Dependencies added: base, filepath, microlens, process
Files
- CHANGELOG.md +5/−0
- LICENSE +30/−0
- README.md +15/−0
- Setup.hs +2/−0
- microlens-process.cabal +43/−0
- src/System/Process/Microlens.hs +34/−0
- src/System/Process/Microlens/CreateProcess.hs +175/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for microlens-process++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2019, Emily Pillmore++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * 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.++ * Neither the name of Emily Pillmore nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++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.
+ README.md view
@@ -0,0 +1,15 @@+# lens-process++[](https://hackage.haskell.org/package/microlens-process)+[](https://travis-ci.org/emilypi/lens-process)++### This package is still in Beta!++This package is intended to be on the lighter side, with few dependencies aside from `microlens`.+++### Motivation++`microlens-process` provides optics for the [process](https://hackage.haskell.org/package/process) package. These optics provide convenient lenses, as well as classy variants for significant classifiable portions of the library for convenience. In addition, we provide some combinators for working with `CreateProcess` types. The intention of this package is to create a well-typed optical layer for `process`, reflecting the shape of certain types of commands at the type level. For instance, consider the following:++For a fuller and more well-typed layer, see [lens-process](https://github.com/emilypi/lens-process)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ microlens-process.cabal view
@@ -0,0 +1,43 @@+cabal-version: >=1.10+-- Initial package description 'microlens-process.cabal' generated by+-- 'cabal init'. For further documentation, see+-- http://haskell.org/cabal/users-guide/++name: microlens-process+version: 0.0.1.0+synopsis: Micro-optics for the process library+description:+ 'microlens-process' is a set of multi-purpose optics and convenience+ combinators for working with the `process` library, including+ a more well-typed api for the parts that can be typed.+homepage: https://github.com/emilypi/lens-process+bug-reports: https://github.com/emilypi/lens-process/issues+license: BSD3+license-file: LICENSE+author: Emily Pillmore+maintainer: emilypi@cohomolo.gy+copyright: (c) 2019 Emily Pillmore+category: System+build-type: Simple+extra-source-files: CHANGELOG.md, README.md+tested-with: GHC == 8.4.3+ , GHC == 8.4.4+ , GHC == 8.6.3+ , GHC == 8.6.5++source-repository head+ type: git+ location: https://github.com/emilypi/lens-process.git++library+ exposed-modules: System.Process.Microlens+ , System.Process.Microlens.CreateProcess+ -- other-modules:+ -- other-extensions:+ build-depends: base >= 4.0 && < 5+ , filepath >= 1.0 && < 1.5+ , microlens >= 0.4.11 && < 4.12+ , process >= 1.4 && < 1.7++ hs-source-dirs: src+ default-language: Haskell2010
+ src/System/Process/Microlens.hs view
@@ -0,0 +1,34 @@+-- |+-- Module : Sysetem.Process.Lens.Optics+-- Copyright : 2019 Emily Pillmore+-- License : BSD+--+-- Maintainer : Emily Pillmore <emilypi@cohomolo.gy>+-- Stability : Experimental+-- Portability : TypeFamilies, Rank2Types+--+-- Just the (classy) optics+--+module System.Process.Microlens+( -- * Lenses+ cmdspec_+, cwd_+, env_+, stdin+, stdout+, stderr+, closefds+, creategroup+, delegatectlc+, detachconsole+, newsession+, childgroup+, childuser+, useprocessjobs+ -- * Classy Lenses+, HasStdin(..)+, HasStdout(..)+, HasStderr(..)+) where++import System.Process.Microlens.CreateProcess
+ src/System/Process/Microlens/CreateProcess.hs view
@@ -0,0 +1,175 @@+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE Rank2Types #-}+-- |+-- Module : Sysetem.Process.Microlens.CreateProcess+-- Copyright : 2019 Emily Pillmore+-- License : BSD+--+-- Maintainer : Emily Pillmore <emilypi@cohomolo.gy>+-- Stability : Experimental+-- Portability : TypeFamilies, Rank2Types+--+-- 'CreateProcess' lenses and combinators+--+module System.Process.Microlens.CreateProcess+( -- * Lenses+ cmdspec_+, cwd_+, env_+, stdin+, stdout+, stderr+, closefds+, creategroup+, createnewconsole+, delegatectlc+, detachconsole+, newsession+, childgroup+, childuser+, useprocessjobs+ -- * Classy Lenses+, HasStdin(..)+, HasStdout(..)+, HasStderr(..)+ -- * Combinators+, closing+) where+++import Lens.Micro++import qualified System.IO as H+import System.Posix.Types+import System.Process+++-- ---------------------------------------------------------- --+-- Optics++-- | Lens into the 'cmdspec' entry of the 'CreateProcess' record+--+cmdspec_ :: Lens' CreateProcess CmdSpec+cmdspec_ = lens cmdspec (\t b -> t { cmdspec = b })++-- | Lens into the 'cwd' entry of the 'CreateProcess' record+--+cwd_ :: Lens' CreateProcess (Maybe FilePath)+cwd_ = lens cwd (\t b -> t { cwd = b })++-- | Lens into the 'env' entry of the 'CreateProcess' record+--+env_ :: Lens' CreateProcess (Maybe [(String, String)])+env_ = lens env (\t b -> t { env = b })++-- | Lens into the 'std_in' entry of the 'CreateProcess' record+--+stdin :: Lens' CreateProcess StdStream+stdin = lens std_in (\t b -> t { std_in = b })++-- | Lens into the 'std_out' entry of the 'CreateProcess' record+--+stdout :: Lens' CreateProcess StdStream+stdout = lens std_out (\t b -> t { std_out = b })++-- | Lens into the 'std_err' entry of the 'CreateProcess' record+--+stderr :: Lens' CreateProcess StdStream+stderr = lens std_err (\t b -> t { std_err = b })++-- | Lens into the 'close_fds' entry of the 'CreateProcess' record+--+closefds :: Lens' CreateProcess Bool+closefds = lens close_fds (\t b -> t { close_fds = b })++-- | Lens into the 'create_group' entry of the 'CreateProcess' record+--+creategroup :: Lens' CreateProcess Bool+creategroup = lens create_group (\t b -> t { create_group = b })++-- | Lens into the 'delegate_ctlc' entry of the 'CreateProcess' record+--+delegatectlc :: Lens' CreateProcess Bool+delegatectlc = lens delegate_ctlc (\t b -> t { delegate_ctlc = b })++-- | Lens into the 'detach_console' entry of the 'CreateProcess' record+--+detachconsole :: Lens' CreateProcess Bool+detachconsole = lens detach_console (\t b -> t { detach_console = b })++-- | Lens into the 'create_new_console' entry of the 'CreateProcess' record+--+createnewconsole :: Lens' CreateProcess Bool+createnewconsole = lens create_new_console (\t b -> t { create_new_console = b })++-- | Lens into the 'new_session' entry of the 'CreateProcess' record+--+newsession :: Lens' CreateProcess Bool+newsession = lens new_session (\t b -> t { new_session = b })++-- | Lens into the 'child_group' entry of the 'CreateProcess' record+--+childgroup :: Lens' CreateProcess (Maybe CGid)+childgroup = lens child_group (\t b -> t { child_group = b })++-- | Lens into the 'child_user' entry of the 'CreateProcess' record+--+childuser :: Lens' CreateProcess (Maybe CUid)+childuser = lens child_user (\t b -> t { child_user = b })++-- | Lens into the 'use_process_jobs' entry of the 'CreateProcess' record+--+useprocessjobs :: Lens' CreateProcess Bool+useprocessjobs = lens use_process_jobs (\t b -> t { use_process_jobs = b })++-- ---------------------------------------------------------- --+-- Classes++-- | Classy lens for types with a stdin+--+class HasStdin a where+ _Stdin :: Lens' a StdStream++instance HasStdin StdStream where+ _Stdin = id++instance HasStdin CreateProcess where+ _Stdin = stdin++-- | Classy lens for types with a stdout+--+class HasStdout a where+ _Stdout :: Lens' a StdStream++instance HasStdout StdStream where+ _Stdout = id++instance HasStdout CreateProcess where+ _Stdout = stdout++-- | Classy lens for types with a stderr+--+class HasStderr a where+ _Stderr :: Lens' a StdStream++instance HasStderr StdStream where+ _Stderr = id++instance HasStderr CreateProcess where+ _Stderr = stderr++-- ---------------------------------------------------------- --+-- Combinators++-- | Close something with a prism into a non-standard 'H.Handle' in a 'CreateProcess'+--+closing :: Lens' CreateProcess StdStream -> CreateProcess -> IO ()+closing l c = case c ^. l of+ UseHandle h -> go h+ _ -> return ()+ where+ go h+ | h /= H.stdin+ , h /= H.stdout+ , h /= H.stderr = H.hClose h+ | otherwise = return ()