Skip to content

Commit

Permalink
Allow show single package
Browse files Browse the repository at this point in the history
  • Loading branch information
nmattia committed Jul 1, 2019
1 parent ad0c892 commit 21e4db8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions script/gen
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 36 additions & 12 deletions src/Niv/Cli.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <> "."
Expand Down

0 comments on commit 21e4db8

Please sign in to comment.