Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog


## [Unreleased]

### Added
* New `version` command: `niv version`

## [0.2.22] 2023-03-12

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ Available commands:
modify Modify dependency attributes without performing an
update
drop Drop dependency
version Print version
```

#### Add
Expand Down
3 changes: 2 additions & 1 deletion app/Niv.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Main where

import Niv.Cli
import System.Environment (getArgs)

main :: IO ()
main = Niv.Cli.cli
main = getArgs >>= Niv.Cli.cli
Comment thread
nmattia marked this conversation as resolved.
3 changes: 1 addition & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

niv-source = sourceByRegex "niv" ./. [
"^niv.cabal$"
"^README.md$"
"^README.md$" # the README is not required for the build but is required for the sdist
"^LICENSE$"
"^app$"
Comment thread
nmattia marked this conversation as resolved.
"^app.*.hs$"
Expand All @@ -41,7 +41,6 @@
"^src/Niv/Sources$"
"^src/Niv/Update$"
"^src.*.hs$"
"^README.md$"
"^nix$"
"^nix.sources.nix$"
];
Expand Down
27 changes: 22 additions & 5 deletions src/Niv/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import qualified Options.Applicative.Help.Pretty as Opts
-- I died a little
import Paths_niv (version)
import qualified System.Directory as Dir
import System.Environment (getArgs)
import System.FilePath (takeDirectory)
import UnliftIO

Expand All @@ -52,17 +51,17 @@ getFindSourcesJson = ask
li :: (MonadIO io) => IO a -> io a
li = liftIO

cli :: IO ()
cli = do
cli :: [String] -> IO ()
cli args = do
((fsj, colors), nio) <-
getArgs >>= Opts.handleParseResult . execParserPure' Opts.defaultPrefs opts
pure args >>= Opts.handleParseResult . execParserPure' Opts.defaultPrefs opts
setColors colors
Comment thread
nmattia marked this conversation as resolved.
runReaderT (runNIO nio) fsj
where
execParserPure' pprefs pinfo [] =
Opts.Failure $
Opts.parserFailure pprefs pinfo (Opts.ShowHelpText Nothing) mempty
execParserPure' pprefs pinfo args = Opts.execParserPure pprefs pinfo args
execParserPure' pprefs pinfo as = Opts.execParserPure pprefs pinfo as
opts = Opts.info ((,) <$> ((,) <$> parseFindSourcesJson <*> parseColors) <*> (parseCommand <**> Opts.helper <**> versionflag)) $ mconcat desc
desc =
[ Opts.fullDesc,
Expand Down Expand Up @@ -105,6 +104,7 @@ parseCommand =
<> Opts.command "update" parseCmdUpdate
<> Opts.command "modify" parseCmdModify
<> Opts.command "drop" parseCmdDrop
<> Opts.command "version" parseCmdVersion
)

parsePackageName :: Opts.Parser PackageName
Expand Down Expand Up @@ -611,6 +611,23 @@ cmdDrop packageName = \case
Sources $
HMS.insert packageName packageSpec sources

-------------------------------------------------------------------------------
-- VERSION
-------------------------------------------------------------------------------

parseCmdVersion :: Opts.ParserInfo (NIO ())
parseCmdVersion =
Opts.info
( pure (tsay $ T.pack $ showVersion version)
<**> Opts.helper
)
$ mconcat desc
where
desc =
[ Opts.fullDesc,
Opts.progDesc "Print version"
]

-------------------------------------------------------------------------------
-- Files and their content
-------------------------------------------------------------------------------
Expand Down