diff --git a/Main.hs b/Main.hs index 9e3a893..c35fcb5 100644 --- a/Main.hs +++ b/Main.hs @@ -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 diff --git a/README.md b/README.md index 262d65f..2012a4e 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/nix/sources.json b/nix/sources.json index e231b68..a808ef5 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -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///archive/.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///archive/.tar.gz","repo":"snack","sha256":"1sywnk19pdj8acq9gb3sy959s55gn66x4s8z038ifimvk6xpyl50","description":"Nix-based incremental build tool for Haskell projects","rev":"a4b7401cd3f7468cc3a8af1067466a96ef259d8b"}} \ No newline at end of file +{ + "snack": { + "homepage": "", + "url": "https://github.com/nmattia/snack/archive/a4b7401cd3f7468cc3a8af1067466a96ef259d8b.tar.gz", + "owner": "nmattia", + "branch": "master", + "url_template": "https://github.com///archive/.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///archive/.tar.gz", + "repo": "nixpkgs-channels", + "sha256": "0h49j1cbnccqx996x80z7na9p7slnj9liz646s73s55am8wc9q8q", + "description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels", + "rev": "138f2cc707d7ee13d93c86db3285460e244c402c" + } +} \ No newline at end of file diff --git a/script/gen b/script/gen new file mode 100755 index 0000000..3090548 --- /dev/null +++ b/script/gen @@ -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