Skip to content
Permalink
Browse files

Allow show single package

  • Loading branch information...
nmattia committed Jul 1, 2019
1 parent ad0c892 commit 21e4db869559477a5b351f5ae1c4aa95619b65d1
Showing with 38 additions and 13 deletions.
  1. +1 −1 README.md
  2. +1 −0 script/gen
  3. +36 −12 src/Niv/Cli.hs
@@ -291,7 +291,7 @@ Available options:
#### show

```
Usage: niv show
Usage: niv show [PACKAGE]
Available options:
-h,--help Show this help text
@@ -2,6 +2,7 @@
#!nix-shell -i bash
#!nix-shell -I nixpkgs=./nix
#!nix-shell -p nix
#!nix-shell --keep SSL_CERT_FILE
#!nix-shell --pure

set -euo pipefail
@@ -266,22 +266,40 @@ cmdAdd mPackageName (PackageName str, cliSpec) = do
-------------------------------------------------------------------------------

parseCmdShow :: Opts.ParserInfo (IO ())
parseCmdShow = Opts.info (pure cmdShow <**> Opts.helper) Opts.fullDesc
parseCmdShow =
Opts.info
((cmdShow <$> Opts.optional parsePackageName) <**> Opts.helper)
Opts.fullDesc

-- TODO: nicer output
cmdShow :: IO ()
cmdShow = do
putStrLn $ "Showing sources file"
cmdShow :: Maybe PackageName -> IO ()
cmdShow = \case
Just packageName -> do
putStrLn $ "Showing package " <> T.unpack (unPackageName packageName)

sources <- unSources <$> getSources
sources <- unSources <$> getSources

forWithKeyM_ sources $ \key (PackageSpec spec) -> do
T.putStrLn $ "Package: " <> unPackageName key
forM_ (HMS.toList spec) $ \(attrName, attrValValue) -> do
let attrValue = case attrValValue of
Aeson.String str -> str
_ -> "<barabajagal>"
putStrLn $ " " <> T.unpack attrName <> ": " <> T.unpack attrValue
case HMS.lookup packageName sources of
Just (PackageSpec spec) -> do
forM_ (HMS.toList spec) $ \(attrName, attrValValue) -> do
let attrValue = case attrValValue of
Aeson.String str -> str
_ -> "<barabajagal>"
putStrLn $ " " <> T.unpack attrName <> ": " <> T.unpack attrValue
Nothing -> abortCannotShowNoSuchPackage packageName

Nothing -> do
putStrLn $ "Showing sources file"

sources <- unSources <$> getSources

forWithKeyM_ sources $ \key (PackageSpec spec) -> do
T.putStrLn $ "Package: " <> unPackageName key
forM_ (HMS.toList spec) $ \(attrName, attrValValue) -> do
let attrValue = case attrValValue of
Aeson.String str -> str
_ -> "<barabajagal>"
putStrLn $ " " <> T.unpack attrName <> ": " <> T.unpack attrValue

-------------------------------------------------------------------------------
-- UPDATE
@@ -635,6 +653,12 @@ abortCannotDropNoSuchPackage (PackageName n) = abort $ T.unlines
, "The package doesn't exist."
]

abortCannotShowNoSuchPackage :: PackageName -> IO a
abortCannotShowNoSuchPackage (PackageName n) = abort $ T.unlines
[ "Cannot show package " <> n <> "."
, "The package doesn't exist."
]

abortCannotAttributesDropNoSuchPackage :: PackageName -> IO a
abortCannotAttributesDropNoSuchPackage (PackageName n) = abort $ T.unlines
[ "Cannot drop attributes of package " <> n <> "."

0 comments on commit 21e4db8

Please sign in to comment.
You can’t perform that action at this time.