1
1
mirror of https://github.com/nmattia/niv.git synced 2024-11-07 22:36:53 +03:00

Merge pull request #14 from nmattia/nm-drop-attr

Implement dropping package attr
This commit is contained in:
Nicolas Mattia 2019-02-08 18:11:37 +00:00 committed by GitHub
commit 697d66c96a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.ParserInfo (IO ())
parseCmdDrop = parseCmdDrop =
Opts.info Opts.info
((cmdDrop <$> parsePackageName) <**> Opts.helper) $ ((cmdDrop <$> parsePackageName <*> parseDropAttributes) <**>
Opts.helper) $
mconcat desc mconcat desc
where where
desc = desc =
@ -442,11 +443,16 @@ parseCmdDrop =
, Opts.headerDoc $ Just $ , Opts.headerDoc $ Just $
"Examples:" Opts.<$$> "Examples:" Opts.<$$>
"" 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 -> [T.Text] -> IO ()
cmdDrop packageName = do cmdDrop packageName = \case
[] -> do
putStrLn $ "Dropping package: " <> unPackageName packageName putStrLn $ "Dropping package: " <> unPackageName packageName
sources <- unSources <$> getSources sources <- unSources <$> getSources
@ -455,6 +461,21 @@ cmdDrop packageName = do
setSources $ Sources $ setSources $ Sources $
HMap.delete packageName 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 -- Aux
@ -694,6 +715,12 @@ abortCannotDropNoSuchPackage (PackageName n) = abort $ unlines
, "The package doesn't exist." , "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 :: IO a
abortNixPrefetchExpectedOutput = abort [s| abortNixPrefetchExpectedOutput = abort [s|
Could not read the output of 'nix-prefetch-url'. This is a bug. Please create a 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: Examples:
niv drop jq niv drop jq
niv drop my-package version
Usage: niv drop PACKAGE Usage: niv drop PACKAGE [ATTRIBUTE]
Drop dependency Drop dependency
Available options: 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