mirror of
https://github.com/nmattia/niv.git
synced 2024-09-19 11:27:40 +03:00
Allow show single package
This commit is contained in:
parent
ad0c8924ed
commit
21e4db8695
@ -291,7 +291,7 @@ Available options:
|
|||||||
#### show
|
#### show
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage: niv show
|
Usage: niv show [PACKAGE]
|
||||||
|
|
||||||
Available options:
|
Available options:
|
||||||
-h,--help Show this help text
|
-h,--help Show this help text
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#!nix-shell -i bash
|
#!nix-shell -i bash
|
||||||
#!nix-shell -I nixpkgs=./nix
|
#!nix-shell -I nixpkgs=./nix
|
||||||
#!nix-shell -p nix
|
#!nix-shell -p nix
|
||||||
|
#!nix-shell --keep SSL_CERT_FILE
|
||||||
#!nix-shell --pure
|
#!nix-shell --pure
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
@ -266,22 +266,40 @@ cmdAdd mPackageName (PackageName str, cliSpec) = do
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
parseCmdShow :: Opts.ParserInfo (IO ())
|
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
|
-- TODO: nicer output
|
||||||
cmdShow :: IO ()
|
cmdShow :: Maybe PackageName -> IO ()
|
||||||
cmdShow = do
|
cmdShow = \case
|
||||||
putStrLn $ "Showing sources file"
|
Just packageName -> do
|
||||||
|
putStrLn $ "Showing package " <> T.unpack (unPackageName packageName)
|
||||||
|
|
||||||
sources <- unSources <$> getSources
|
sources <- unSources <$> getSources
|
||||||
|
|
||||||
forWithKeyM_ sources $ \key (PackageSpec spec) -> do
|
case HMS.lookup packageName sources of
|
||||||
T.putStrLn $ "Package: " <> unPackageName key
|
Just (PackageSpec spec) -> do
|
||||||
forM_ (HMS.toList spec) $ \(attrName, attrValValue) -> do
|
forM_ (HMS.toList spec) $ \(attrName, attrValValue) -> do
|
||||||
let attrValue = case attrValValue of
|
let attrValue = case attrValValue of
|
||||||
Aeson.String str -> str
|
Aeson.String str -> str
|
||||||
_ -> "<barabajagal>"
|
_ -> "<barabajagal>"
|
||||||
putStrLn $ " " <> T.unpack attrName <> ": " <> T.unpack attrValue
|
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
|
-- UPDATE
|
||||||
@ -635,6 +653,12 @@ abortCannotDropNoSuchPackage (PackageName n) = abort $ T.unlines
|
|||||||
, "The package doesn't exist."
|
, "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 -> IO a
|
||||||
abortCannotAttributesDropNoSuchPackage (PackageName n) = abort $ T.unlines
|
abortCannotAttributesDropNoSuchPackage (PackageName n) = abort $ T.unlines
|
||||||
[ "Cannot drop attributes of package " <> n <> "."
|
[ "Cannot drop attributes of package " <> n <> "."
|
||||||
|
Loading…
Reference in New Issue
Block a user