1
1
mirror of https://github.com/nmattia/niv.git synced 2024-09-18 19:07:19 +03:00

Allow show single package

This commit is contained in:
Nicolas Mattia 2019-07-01 17:29:37 +02:00
parent ad0c8924ed
commit 21e4db8695
3 changed files with 38 additions and 13 deletions

View File

@ -291,7 +291,7 @@ Available options:
#### show
```
Usage: niv show
Usage: niv show [PACKAGE]
Available options:
-h,--help Show this help text

View File

@ -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

View File

@ -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 <> "."