packages feed

nix-diff 1.0.4 → 1.0.5

raw patch · 3 files changed

+71/−22 lines, 3 filesdep +optparse-applicativedep −optparse-generic

Dependencies added: optparse-applicative

Dependencies removed: optparse-generic

Files

README.md view
@@ -1,4 +1,4 @@-# `nix-diff 1.0.4`+# `nix-diff 1.0.5`  This package provides a `nix-diff` executable which explains why two Nix derivations differ.  The most common use cases for this are:
nix-diff.cabal view
@@ -1,5 +1,5 @@ name:                nix-diff-version:             1.0.4+version:             1.0.5 synopsis:            Explain why two Nix derivations differ description:         This package provides a @nix-diff@ executable which                      explains why two Nix derivations (i.e. @*.drv@ files)@@ -18,16 +18,16 @@  executable nix-diff   main-is:             Main.hs-  build-depends:       base             >= 4.9  && < 5-                     , attoparsec       >= 0.13 && < 0.14-                     , containers       >= 0.5  && < 0.6-                     , Diff             >= 0.3  && < 0.4-                     , text             >= 1.2  && < 1.3-                     , system-filepath  >= 0.4  && < 0.5-                     , optparse-generic >= 1.1  && < 1.4-                     , nix-derivation   >= 1.0  && < 1.1-                     , mtl              >= 2.2  && < 2.3-                     , unix                        < 2.8-                     , vector           >= 0.12 && < 0.13+  build-depends:       base                 >= 4.9      && < 5+                     , attoparsec           >= 0.13     && < 0.14+                     , containers           >= 0.5      && < 0.6+                     , Diff                 >= 0.3      && < 0.4+                     , text                 >= 1.2      && < 1.3+                     , system-filepath      >= 0.4      && < 0.5+                     , optparse-applicative >= 0.14.0.0 && < 0.15+                     , nix-derivation       >= 1.0      && < 1.1+                     , mtl                  >= 2.2      && < 2.3+                     , unix                                < 2.8+                     , vector               >= 0.12     && < 0.13   hs-source-dirs:      src   default-language:    Haskell2010
src/Main.hs view
@@ -1,10 +1,11 @@-{-# LANGUAGE DeriveGeneric              #-}+{-# LANGUAGE ApplicativeDo              #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE NamedFieldPuns             #-} {-# LANGUAGE OverloadedStrings          #-}  module Main where +import Control.Applicative ((<|>)) import Control.Monad (forM, forM_) import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad.Reader (MonadReader, ReaderT, ask, local)@@ -18,7 +19,7 @@ import Filesystem.Path (FilePath) import Nix.Derivation (Derivation, DerivationOutput) import Numeric.Natural (Natural)-import Options.Generic (Generic, ParseRecord)+import Options.Applicative (Parser, ParserInfo) import Prelude hiding (FilePath)  import qualified Control.Monad.Reader@@ -32,15 +33,55 @@ import qualified Data.Vector import qualified Filesystem.Path.CurrentOS import qualified Nix.Derivation-import qualified Options.Generic+import qualified Options.Applicative import qualified System.Posix.IO import qualified System.Posix.Terminal -data Options = Options FilePath FilePath-    deriving (Generic)+data Color = Always | Auto | Never -instance ParseRecord Options+parseColor :: Parser Color+parseColor =+    Options.Applicative.option+        reader+        (   Options.Applicative.long "color"+        <>  Options.Applicative.value Auto+        <>  Options.Applicative.metavar "(always|auto|never)"+        )+  where+    reader = do+        string <- Options.Applicative.str+        case string of+            "always" -> return Always+            "auto"   -> return Auto+            "never"  -> return Never+            _        -> fail "Invalid color" +data Options = Options { left :: FilePath, right :: FilePath, color :: Color }++parseOptions :: Parser Options+parseOptions = do+    left  <- parseLeft+    right <- parseRight+    color <- parseColor++    return (Options { left, right, color })+  where+    parseFilePath metavar = do+        Options.Applicative.strArgument+            (Options.Applicative.metavar metavar)++    parseLeft = parseFilePath "LEFT"++    parseRight = parseFilePath "RIGHT"++parserInfo :: ParserInfo Options+parserInfo =+    Options.Applicative.info+        parseOptions+        (   Options.Applicative.fullDesc+        <>  Options.Applicative.header "Explain why two derivations differ"+        )+ data Context = Context     { tty    :: TTY     , indent :: Natural@@ -458,9 +499,17 @@  main :: IO () main = do-    Options left right <- Options.Generic.getRecord "Explain why two derivations differ"-    b <- System.Posix.Terminal.queryTerminal System.Posix.IO.stdOutput-    let tty = if b then IsTTY else NotTTY+    Options { left, right, color } <- Options.Applicative.execParser parserInfo++    tty <- case color of+        Never -> do+            return NotTTY+        Always -> do+            return IsTTY+        Auto -> do+            b <- System.Posix.Terminal.queryTerminal System.Posix.IO.stdOutput+            return (if b then IsTTY else NotTTY)+     let indent = 0     let context = Context { tty, indent }     let status = Status Data.Set.empty