gw (empty) → 0.1
raw patch · 5 files changed
+261/−0 lines, 5 filesdep +basedep +unix
Dependencies added: base, unix
Files
- CHANGELOG.md +12/−0
- LICENSE +29/−0
- README.md +6/−0
- app/Main.hs +156/−0
- gw.cabal +58/−0
+ CHANGELOG.md view
@@ -0,0 +1,12 @@+# Changelog++`gw` uses [PVP Versioning][1].+The changelog is available [on GitHub][2].++0.0.0+=====++* Initially created.++[1]: https://pvp.haskell.org+[2]: https://github.com/chessai/gw/releases
+ LICENSE view
@@ -0,0 +1,29 @@+BSD 3-Clause License++Copyright (c) 2019, chessai+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer.++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 copyright holder nor the names of its+ 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 HOLDER 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,6 @@+# gw++[](https://hackage.haskell.org/package/gw)+[](LICENSE)++ghcWithPackages cmdline util
+ app/Main.hs view
@@ -0,0 +1,156 @@+{-# language DerivingStrategies #-}+{-# language GeneralizedNewtypeDeriving #-}+{-# language LambdaCase #-}+{-# language OverloadedStrings #-}+{-# language ScopedTypeVariables #-}+{-# language ViewPatterns #-}++module Main+ ( main+ ) where++import System.Environment (getArgs)+import qualified Data.List as List+import qualified System.Posix.Process as P++main :: IO ()+main = parseArgs >>= runCmd++parseArgs :: IO Cmd+parseArgs = getArgs >>= \case+ [] -> pure Help+ ("-v":_) -> pure Version+ ("--version":_) -> pure Version+ ("-h":_) -> pure Help+ ("--help":_) -> pure Help+ ("-p":xs) -> go Pure xs+ ("--pure":xs) -> go Pure xs+ xs -> go Impure xs+ where+ go :: Purity -> [String] -> IO Cmd+ go p = \case+ [] -> pure BadCmd+ (x:xs) -> case readGhc x of+ Left str -> do+ putStr (str ++ "\n")+ pure BadCmd+ Right g -> pure $ GhcWith p g (PkgSet xs)++ghcWith :: Ghc -> PkgSet -> String+ghcWith (showGhc -> ghc) (showPkgSet -> pkgs) = mconcat+ [ "haskell.packages."+ , ghc+ , ".ghcWithPackages (pkgs: with pkgs; [ "+ , pkgs+ , " ])"+ ]++ghcWithIO :: Ghc -> PkgSet -> Purity -> IO ()+ghcWithIO g pkgs p+ = P.executeFile "nix-shell" True (p' ++ ["-p",ghcWith g pkgs]) Nothing + where+ p' = case p of+ Pure -> ["--pure"]+ Impure -> []++data Cmd+ = Help+ | Version+ | GhcWith Purity Ghc PkgSet+ | BadCmd++runCmd :: Cmd -> IO ()+runCmd = \case+ Help -> putStr help+ Version -> putStr version+ GhcWith p g pkgs -> ghcWithIO g pkgs p+ BadCmd -> putStr badCmd++help,version,badCmd :: String+help = mconcat+ [ "\n"+ , " gw - a utility for entering a nix-shell using ghcWithPackages\n\n"+ , " Usage: gw <OPTIONS> <GHC> <PKGS>\n\n"+ , " Available options:\n"+ , " -h,--help Display this help menu\n"+ , " -p,--pure Enter a pure nix-shell\n"+ , " -v,--version Display the version of gw\n"+ , "\n"+ ]+version = "gw 0.1"+badCmd = mconcat+ [ "\n"+ , "Malformed command. Help menu:\n"+ , help+ ]++readGhc :: String -> Either String Ghc+readGhc = \case+ "ghc710" -> Right Ghc710+ "ghc801" -> Right Ghc801+ "ghc802" -> Right Ghc802+ "ghc821" -> Right Ghc821+ "ghc822" -> Right Ghc822+ "ghc841" -> Right Ghc841+ "ghc842" -> Right Ghc842+ "ghc843" -> Right Ghc843+ "ghc844" -> Right Ghc844+ "ghc861" -> Right Ghc861+ "ghc862" -> Right Ghc862+ "ghc863" -> Right Ghc863+ "ghc864" -> Right Ghc864+ "ghc865" -> Right Ghc865+ "ghcHEAD" -> Right GhcHead+ x -> Left $ "GHC arg \"" ++ x ++ "\" passed is not one of " ++ ghcSet++showGhc :: Ghc -> String+showGhc = \case+ Ghc710 -> "ghc710"+ Ghc801 -> "ghc801"+ Ghc802 -> "ghc802"+ Ghc821 -> "ghc821"+ Ghc822 -> "ghc822"+ Ghc841 -> "ghc841"+ Ghc842 -> "ghc842"+ Ghc843 -> "ghc843"+ Ghc844 -> "ghc844"+ Ghc861 -> "ghc861"+ Ghc862 -> "ghc862"+ Ghc863 -> "ghc863"+ Ghc864 -> "ghc864"+ Ghc865 -> "ghc865"+ GhcHead -> "ghcHEAD"+ +data Ghc+ = Ghc710+ | Ghc801+ | Ghc802+ | Ghc821+ | Ghc822+ | Ghc841+ | Ghc842+ | Ghc843+ | Ghc844+ | Ghc861+ | Ghc862+ | Ghc863+ | Ghc864+ | Ghc865+ | GhcHead+ deriving stock (Eq,Ord,Enum,Bounded,Show)++ghcSet :: String+ghcSet = mconcat+ [ "{"+ , (List.intercalate ", " (map showGhc [minBound..maxBound :: Ghc]))+ , "}"+ ]++newtype PkgSet = PkgSet [String]+ deriving newtype (Eq,Show)++showPkgSet :: PkgSet -> String+showPkgSet (PkgSet set) = List.unwords set++data Purity = Pure | Impure+ deriving stock (Eq,Show)
+ gw.cabal view
@@ -0,0 +1,58 @@+cabal-version: 2.2+name:+ gw+version:+ 0.1+synopsis:+ ghcWithPackages cmdline util+description:+ ghcWithPackages cmdline util. supports:+ . + * multiple ghc versions+ . + * pure/impure nix-shell+ . + * entering shell with multiple packages available+ +homepage:+ https://github.com/chessai/gw+bug-reports:+ https://github.com/chessai/gw/issues+license:+ BSD-3-Clause+license-file:+ LICENSE+author:+ chessai+maintainer:+ chessai <chessai1996@gmail.com>+copyright:+ © 2019 chessai+category:+ Utility+build-type:+ Simple+extra-doc-files:+ README.md+ , CHANGELOG.md+tested-with:+ GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.3++executable gw+ hs-source-dirs:+ app+ main-is:+ Main.hs+ build-depends:+ , base >= 4.10.1 && < 4.13+ , unix >= 2.7 && < 2.8+ ghc-options:+ -Wall+ default-language:+ Haskell2010++source-repository head+ type:+ git+ location:+ https://github.com/chessai/gw.git