Options/Parser: add '--long-version' that adds debug information (#712)

Option for debugging and bugreporting purposes.

Current output:
```
Version: 0.9.1
Commit: 2dc211314e
  date: Sat Sep 12 13:31:59 2020 +0300
  branch: 2020-09-12-add-GitRev-to-version
```

Also date and branch is to direct contributors attention to updating (or having
in mind) that.

M  hnix.cabal
M  src/Nix/Options/Parser.hs
This commit is contained in:
Anton Latukha 2020-09-13 13:51:14 +03:00 committed by GitHub
parent 775be0d234
commit 83c5cea9a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 7 deletions

View File

@ -398,6 +398,7 @@ library
, exceptions >= 0.10.0 && < 0.11
, filepath >= 1.4.2 && < 1.5
, free >= 5.1 && < 5.2
, gitrev >= 1.1.0 && < 1.4
, hashable >= 1.2.5 && < 1.4
, hashing >= 0.1.0 && < 0.2
, hnix-store-core >= 0.1.0 && < 0.3

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Nix.Options.Parser where
import Control.Arrow ( second )
@ -8,8 +10,11 @@ import qualified Data.Text as Text
import Data.Time
import Nix.Options
import Options.Applicative hiding ( ParserResult(..) )
import Data.Version (showVersion)
import Paths_hnix (version)
import Data.Version ( showVersion )
import Development.GitRev ( gitCommitDate
, gitBranch
, gitHash )
import Paths_hnix ( version )
decodeVerbosity :: Int -> Verbosity
decodeVerbosity 0 = ErrorsOnly
@ -183,12 +188,29 @@ nixOptions current =
)
)
-- 2020-09-12: CLI --version option mechanism is tied to meta modules specificly generated by Cabal. It is possible to use Template Haskell to resolve the version, as also a g
versionOpt :: Parser (a -> a)
versionOpt = infoOption
(showVersion version)
( long "version"
<> help "Show release version"
)
versionOpt = shortVersionOpt <*> debugVersionOpt
where
shortVersionOpt :: Parser (a -> a)
shortVersionOpt = infoOption
(showVersion version)
( long "version"
<> help "Show release version"
)
debugVersionOpt :: Parser (a -> a)
debugVersionOpt = infoOption
( concat
[ "Version: ", showVersion version
, "\nCommit: ", $(gitHash)
, "\n date: ", $(gitCommitDate)
, "\n branch: ", $(gitBranch)
]
)
( long "long-version"
<> help "Show long debug version form"
)
nixOptionsInfo :: UTCTime -> ParserInfo Options
nixOptionsInfo current = info (helper <*> versionOpt <*> nixOptions current)