1
1
mirror of https://github.com/nmattia/niv.git synced 2024-11-27 01:56:09 +03:00

Implement dropping package attr

This commit is contained in:
Nicolas Mattia 2019-02-08 19:07:05 +01:00
parent 497d602e36
commit a180f5c130
4 changed files with 67 additions and 6 deletions

35
Main.hs
View File

@ -433,7 +433,8 @@ cmdUpdate = \case
parseCmdDrop :: Opts.ParserInfo (IO ())
parseCmdDrop =
Opts.info
((cmdDrop <$> parsePackageName) <**> Opts.helper) $
((cmdDrop <$> parsePackageName <*> parseDropAttributes) <**>
Opts.helper) $
mconcat desc
where
desc =
@ -442,11 +443,16 @@ parseCmdDrop =
, Opts.headerDoc $ Just $
"Examples:" Opts.<$$>
"" Opts.<$$>
" niv drop jq"
" niv drop jq" Opts.<$$>
" niv drop my-package version"
]
parseDropAttributes :: Opts.Parser [T.Text]
parseDropAttributes = many $
Opts.argument Opts.str (Opts.metavar "ATTRIBUTE")
cmdDrop :: PackageName -> IO ()
cmdDrop packageName = do
cmdDrop :: PackageName -> [T.Text] -> IO ()
cmdDrop packageName = \case
[] -> do
putStrLn $ "Dropping package: " <> unPackageName packageName
sources <- unSources <$> getSources
@ -455,6 +461,21 @@ cmdDrop packageName = do
setSources $ Sources $
HMap.delete packageName sources
attrs -> do
putStrLn $ "Dropping attributes :" <>
(T.unpack (T.intercalate " " attrs))
putStrLn $ "In package: " <> unPackageName packageName
sources <- unSources <$> getSources
packageSpec <- case HMap.lookup packageName sources of
Nothing ->
abortCannotAttributesDropNoSuchPackage packageName
Just (PackageSpec packageSpec) -> pure $ PackageSpec $
HMap.mapMaybeWithKey
(\k v -> if k `elem` attrs then Nothing else Just v) packageSpec
setSources $ Sources $
HMap.insert packageName packageSpec sources
-------------------------------------------------------------------------------
-- Aux
@ -694,6 +715,12 @@ abortCannotDropNoSuchPackage (PackageName n) = abort $ unlines
, "The package doesn't exist."
]
abortCannotAttributesDropNoSuchPackage :: PackageName -> IO a
abortCannotAttributesDropNoSuchPackage (PackageName n) = abort $ unlines
[ "Cannot drop attributes of package " <> n <> "."
, "The package doesn't exist."
]
abortNixPrefetchExpectedOutput :: IO a
abortNixPrefetchExpectedOutput = abort [s|
Could not read the output of 'nix-prefetch-url'. This is a bug. Please create a

View File

@ -104,8 +104,9 @@ Available options:
Examples:
niv drop jq
niv drop my-package version
Usage: niv drop PACKAGE
Usage: niv drop PACKAGE [ATTRIBUTE]
Drop dependency
Available options:

View File

@ -1 +1,23 @@
{"nixpkgs":{"url":"https://github.com/NixOS/nixpkgs-channels/archive/138f2cc707d7ee13d93c86db3285460e244c402c.tar.gz","owner":"NixOS","branch":"nixos-18.03","url_template":"https://github.com/<owner>/<repo>/archive/<rev>.tar.gz","repo":"nixpkgs-channels","sha256":"0h49j1cbnccqx996x80z7na9p7slnj9liz646s73s55am8wc9q8q","description":"Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels","rev":"138f2cc707d7ee13d93c86db3285460e244c402c"},"snack":{"homepage":"","url":"https://github.com/nmattia/snack/archive/a4b7401cd3f7468cc3a8af1067466a96ef259d8b.tar.gz","owner":"nmattia","branch":"master","url_template":"https://github.com/<owner>/<repo>/archive/<rev>.tar.gz","repo":"snack","sha256":"1sywnk19pdj8acq9gb3sy959s55gn66x4s8z038ifimvk6xpyl50","description":"Nix-based incremental build tool for Haskell projects","rev":"a4b7401cd3f7468cc3a8af1067466a96ef259d8b"}}
{
"snack": {
"homepage": "",
"url": "https://github.com/nmattia/snack/archive/a4b7401cd3f7468cc3a8af1067466a96ef259d8b.tar.gz",
"owner": "nmattia",
"branch": "master",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
"repo": "snack",
"sha256": "1sywnk19pdj8acq9gb3sy959s55gn66x4s8z038ifimvk6xpyl50",
"description": "Nix-based incremental build tool for Haskell projects",
"rev": "a4b7401cd3f7468cc3a8af1067466a96ef259d8b"
},
"nixpkgs": {
"url": "https://github.com/NixOS/nixpkgs-channels/archive/138f2cc707d7ee13d93c86db3285460e244c402c.tar.gz",
"owner": "NixOS",
"branch": "nixos-18.03",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
"repo": "nixpkgs-channels",
"sha256": "0h49j1cbnccqx996x80z7na9p7slnj9liz646s73s55am8wc9q8q",
"description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels",
"rev": "138f2cc707d7ee13d93c86db3285460e244c402c"
}
}

11
script/gen Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash
#!nix-shell -I nixpkgs=./nix
#!nix-shell -p nix
#!nix-shell --pure
set -euo pipefail
echo "Updating README"
cat $(nix-build -A readme) > README.md