niv 0.2.18 → 0.2.19
raw patch · 8 files changed
+93/−46 lines, 8 files
Files
- README.md +6/−2
- niv.cabal +2/−2
- nix/sources.nix +4/−1
- src/Niv/Cli.hs +9/−2
- src/Niv/Git/Cmd.hs +15/−6
- src/Niv/GitHub.hs +3/−3
- src/Niv/Logger.hs +50/−30
- src/Niv/Sources.hs +4/−0
README.md view
@@ -205,6 +205,9 @@ template that can be reused by niv when fetching a new URL (see the documentation for [add](#add) and [update](#update)). +The type of the dependency is guessed from the provided URL template, if `-T`+is not specified.+ For updating the version of GHC used run this command: ``` shell@@ -216,12 +219,13 @@ ``` niv - dependency manager for Nix projects -version: 0.2.18+version: 0.2.19 -Usage: niv [-s|--sources-file FILE] COMMAND+Usage: niv [-s|--sources-file FILE] [--no-colors] COMMAND Available options: -s,--sources-file FILE Use FILE instead of nix/sources.json+ --no-colors Don't use colors in output -h,--help Show this help text --version Print version
niv.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: f33a4bacf65fdd3b3ad1ee550d862cd5394d00eb4c7f2bf5c51890eb76124fbb+-- hash: 6551d56f4a527a8b959ff8a47f1bf12e96efb5c6f62bb82d4c61cfb92ff1544f name: niv-version: 0.2.18+version: 0.2.19 synopsis: Easy dependency management for Nix projects description: Easy dependency management for Nix projects. category: Development
nix/sources.nix view
@@ -98,7 +98,10 @@ saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; in- if ersatz == "" then drv else ersatz;+ if ersatz == "" then drv else+ # this turns the string into an actual Nix path (for both absolute and+ # relative paths)+ if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions
src/Niv/Cli.hs view
@@ -54,16 +54,17 @@ cli :: IO () cli = do warnGitHubEnvVars- (fsj, nio) <-+ ((fsj, colors), nio) <- execParserPure' Opts.defaultPrefs opts <$> getArgs >>= Opts.handleParseResult+ setColors colors runReaderT (runNIO nio) fsj where execParserPure' pprefs pinfo [] = Opts.Failure $ Opts.parserFailure pprefs pinfo Opts.ShowHelpText mempty execParserPure' pprefs pinfo args = Opts.execParserPure pprefs pinfo args- opts = Opts.info ((,) <$> parseFindSourcesJson <*> (parseCommand <**> Opts.helper <**> versionflag)) $ mconcat desc+ opts = Opts.info ((,) <$> ((,) <$> parseFindSourcesJson <*> parseColors) <*> (parseCommand <**> Opts.helper <**> versionflag)) $ mconcat desc desc = [ Opts.fullDesc, Opts.headerDoc $ Just $@@ -80,6 +81,12 @@ <> Opts.help "Use FILE instead of nix/sources.json" ) <|> pure Auto+ parseColors =+ (\case True -> Never; False -> Always)+ <$> Opts.switch+ ( Opts.long "no-colors"+ <> Opts.help "Don't use colors in output"+ ) versionflag :: Opts.Parser (a -> a) versionflag = Opts.abortOption (Opts.InfoMsg (showVersion version)) $
src/Niv/Git/Cmd.hs view
@@ -181,9 +181,9 @@ abortNoOutput args = abortGitFailure args- "Git didn't produce any output."+ $ "Git didn't produce any output. Does the branch '" <> branch <> "' exist?" abortTooMuchOutput args ls =- abortGitFailure args $ T.unlines $+ abortGitBug args $ T.unlines $ ["Git produced too much output:"] <> map (" " <>) ls defaultBranchAndRev ::@@ -195,7 +195,7 @@ case sout of (l1 : l2 : _) -> (,) <$> parseBranch l1 <*> parseRev l2 _ ->- abortGitFailure args $ T.unlines $+ abortGitBug args $ T.unlines $ [ "Could not read reference and revision from stdout:" ] <> sout@@ -211,10 +211,10 @@ checkRev t = if isRev t then Just t else Nothing abortNoRev :: [T.Text] -> T.Text -> IO a-abortNoRev args l = abortGitFailure args $ "Could not read revision from: " <> l+abortNoRev args l = abortGitBug args $ "Could not read revision from: " <> l abortNoRef :: [T.Text] -> T.Text -> IO a-abortNoRef args l = abortGitFailure args $ "Could not read reference from: " <> l+abortNoRef args l = abortGitBug args $ "Could not read reference from: " <> l -- | Run the "git" executable runGit :: [T.Text] -> IO [T.Text]@@ -223,7 +223,7 @@ case (exitCode, lines sout) of (ExitSuccess, ls) -> pure $ T.pack <$> ls _ ->- abortGitFailure args $+ abortGitBug args $ T.unlines [ T.unwords ["stdout:", T.pack sout], T.unwords ["stderr:", T.pack serr]@@ -239,6 +239,15 @@ abortGitFailure :: [T.Text] -> T.Text -> IO a abortGitFailure args msg =+ abort $+ T.unlines+ [ "Could not read the output of 'git'.",+ T.unwords ("command:" : "git" : args),+ msg+ ]++abortGitBug :: [T.Text] -> T.Text -> IO a+abortGitBug args msg = abort $ bug $ T.unlines [ "Could not read the output of 'git'.",
src/Niv/GitHub.hs view
@@ -34,9 +34,9 @@ <<< (useOrSet "url_template" <<< completeSpec) <+> (load "url_template") -< () url <- update "url" -< urlTemplate- let isTar = (\u -> "tar.gz" `T.isSuffixOf` u || ".tgz" `T.isSuffixOf` u) <$> url- useOrSet "type" -< bool "file" "tarball" <$> isTar :: Box T.Text- let doUnpack = isTar+ let isTarGuess = (\u -> "tar.gz" `T.isSuffixOf` u || ".tgz" `T.isSuffixOf` u) <$> url+ type' <- useOrSet "type" -< bool "file" "tarball" <$> isTarGuess :: Box T.Text+ let doUnpack = (== "tarball") <$> type' _sha256 <- update "sha256" <<< run (\(up, u) -> prefetch up u) -< (,) <$> doUnpack <*> url returnA -< () where
src/Niv/Logger.hs view
@@ -4,7 +4,9 @@ {-# LANGUAGE OverloadedStrings #-} module Niv.Logger- ( job,+ ( Colors (Always, Never),+ job,+ setColors, bug, tsay, say,@@ -35,6 +37,27 @@ import System.IO.Unsafe (unsafePerformIO) import UnliftIO +-- A somewhat hacky way of deciding whether or not to use SGR codes, by writing+-- and reading a global variable unsafely.+-- This should be fine as long as the IORef is written right after argument+-- parsing, and as long as the value is never changed.+-- NOTE: this won't work in GHCi.++data Colors+ = Always+ | Never+ deriving (Eq)++colors :: IORef Colors+colors = unsafePerformIO $ newIORef Always+{-# NOINLINE colors #-}++setColors :: Colors -> IO ()+setColors = writeIORef colors++useColors :: Bool+useColors = unsafePerformIO $ (\c -> c == Always) <$> readIORef colors+ type S = String -> String type T = T.Text -> T.Text@@ -85,61 +108,58 @@ mkNote :: T.Text -> T.Text mkNote w = tbold (tblue "NOTE") <> ": " <> w +color :: ANSI.Color -> String -> String+color c str =+ if useColors+ then+ ANSI.setSGRCode [ANSI.SetConsoleIntensity ANSI.BoldIntensity]+ <> ANSI.setSGRCode [ANSI.SetColor ANSI.Foreground ANSI.Vivid c]+ <> str+ <> ANSI.setSGRCode [ANSI.Reset]+ else str++colorFaint :: ANSI.Color -> String -> String+colorFaint c str =+ if useColors+ then+ ANSI.setSGRCode [ANSI.SetConsoleIntensity ANSI.FaintIntensity]+ <> ANSI.setSGRCode [ANSI.SetColor ANSI.Foreground ANSI.Vivid c]+ <> str+ <> ANSI.setSGRCode [ANSI.Reset]+ else str+ green :: S-green str =- ANSI.setSGRCode [ANSI.SetConsoleIntensity ANSI.BoldIntensity]- <> ANSI.setSGRCode [ANSI.SetColor ANSI.Foreground ANSI.Vivid ANSI.Green]- <> str- <> ANSI.setSGRCode [ANSI.Reset]+green = color ANSI.Green tgreen :: T tgreen = t green yellow :: S-yellow str =- ANSI.setSGRCode [ANSI.SetConsoleIntensity ANSI.BoldIntensity]- <> ANSI.setSGRCode [ANSI.SetColor ANSI.Foreground ANSI.Vivid ANSI.Yellow]- <> str- <> ANSI.setSGRCode [ANSI.Reset]+yellow = color ANSI.Yellow tyellow :: T tyellow = t yellow blue :: S-blue str =- ANSI.setSGRCode [ANSI.SetConsoleIntensity ANSI.BoldIntensity]- <> ANSI.setSGRCode [ANSI.SetColor ANSI.Foreground ANSI.Vivid ANSI.Blue]- <> str- <> ANSI.setSGRCode [ANSI.Reset]+blue = color ANSI.Blue tblue :: T tblue = t blue red :: S-red str =- ANSI.setSGRCode [ANSI.SetColor ANSI.Foreground ANSI.Vivid ANSI.Red]- <> str- <> ANSI.setSGRCode [ANSI.Reset]+red = color ANSI.Red tred :: T tred = t red bold :: S-bold str =- ANSI.setSGRCode [ANSI.SetConsoleIntensity ANSI.BoldIntensity]- <> ANSI.setSGRCode [ANSI.SetColor ANSI.Foreground ANSI.Vivid ANSI.White]- <> str- <> ANSI.setSGRCode [ANSI.Reset]+bold = color ANSI.White tbold :: T tbold = t bold faint :: String -> String-faint str =- ANSI.setSGRCode [ANSI.SetConsoleIntensity ANSI.FaintIntensity]- <> ANSI.setSGRCode [ANSI.SetColor ANSI.Foreground ANSI.Vivid ANSI.White]- <> str- <> ANSI.setSGRCode [ANSI.Reset]+faint = colorFaint ANSI.White tfaint :: T tfaint = t faint
src/Niv/Sources.hs view
@@ -170,6 +170,8 @@ V22 | -- Allow to pass custom system to bootstrap niv in pure mode V23+ | -- Fix NIV_OVERRIDE_{name} for sandbox+ V24 deriving stock (Bounded, Enum, Eq) -- | A user friendly version@@ -198,6 +200,7 @@ V21 -> "21" V22 -> "22" V23 -> "23"+ V24 -> "24" latestVersionMD5 :: T.Text latestVersionMD5 = sourcesVersionToMD5 maxBound@@ -233,6 +236,7 @@ V21 -> "c501eee378828f7f49828a140dbdbca3" V22 -> "935d1d2f0bf95fda977a6e3a7e548ed4" V23 -> "4111204b613ec688e2669516dd313440"+ V24 -> "116c2d936f1847112fef0013771dab28" -- | The MD5 sum of ./nix/sources.nix sourcesNixMD5 :: IO T.Text