Add --version and --numeric-version

This commit is contained in:
Julian Ospald 2020-04-17 16:56:56 +02:00
parent 9d9e415a09
commit eaafd77a7e
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
3 changed files with 33 additions and 8 deletions

View File

@ -17,6 +17,7 @@ import GHCup.Platform
import GHCup.Requirements import GHCup.Requirements
import GHCup.Types import GHCup.Types
import GHCup.Utils import GHCup.Utils
import GHCup.Utils.File
import GHCup.Utils.Logger import GHCup.Utils.Logger
import GHCup.Utils.Prelude import GHCup.Utils.Prelude
import GHCup.Version import GHCup.Version
@ -40,6 +41,7 @@ import GHC.IO.Encoding
import Haskus.Utils.Variant.Excepts import Haskus.Utils.Variant.Excepts
import HPath import HPath
import HPath.IO import HPath.IO
import Language.Haskell.TH
import Options.Applicative hiding ( style ) import Options.Applicative hiding ( style )
import Prelude hiding ( appendFile ) import Prelude hiding ( appendFile )
import System.Console.Pretty import System.Console.Pretty
@ -81,7 +83,6 @@ data Command
| DInfo | DInfo
| Compile CompileCommand | Compile CompileCommand
| Upgrade UpgradeOpts Bool | Upgrade UpgradeOpts Bool
| NumericVersion
| ToolRequirements | ToolRequirements
data ToolVersion = ToolVersion Version data ToolVersion = ToolVersion Version
@ -213,11 +214,6 @@ com =
( command ( command
"debug-info" "debug-info"
((\_ -> DInfo) <$> (info (helper) (progDesc "Show debug info"))) ((\_ -> DInfo) <$> (info (helper) (progDesc "Show debug info")))
<> command
"numeric-version"
( (\_ -> NumericVersion)
<$> (info (helper) (progDesc "Show the numeric version"))
)
<> command <> command
"tool-requirements" "tool-requirements"
( (\_ -> ToolRequirements) ( (\_ -> ToolRequirements)
@ -518,11 +514,35 @@ upgradeOptsP =
describe_result :: String
describe_result = $( (LitE . StringL) <$>
runIO (do
CapturedProcess{..} <- executeOut [rel|git|] ["describe"] Nothing
case _exitCode of
ExitSuccess -> pure . T.unpack . decUTF8Safe $ _stdOut
ExitFailure _ -> pure numericVer
)
)
main :: IO () main :: IO ()
main = do main = do
let
versionHelp = infoOption
(("The GHCup Haskell installer, version " <>
)
$ (head . lines $ describe_result)
)
(long "version" <> help "Show version")
let numericVersionHelp = infoOption
numericVer
( long "numeric-version"
<> help "Show the numeric version (for use in scripts)"
)
customExecParser (prefs showHelpOnError) (info (opts <**> helper) idm) customExecParser
(prefs showHelpOnError)
(info (opts <**> helper <**> versionHelp <**> numericVersionHelp) idm)
>>= \opt@Options {..} -> do >>= \opt@Options {..} -> do
let settings = toSettings opt let settings = toSettings opt
@ -802,7 +822,6 @@ Check the logs at ~/.ghcup/logs and the build directory #{tmpdir} for more clues
VLeft e -> VLeft e ->
runLogger ($(logError) [i|#{e}|]) >> exitFailure runLogger ($(logError) [i|#{e}|]) >> exitFailure
NumericVersion -> T.hPutStr stdout (prettyPVP ghcUpVer)
ToolRequirements -> (runLogger $ runE ToolRequirements -> (runLogger $ runE
@'[ NoCompatiblePlatform @'[ NoCompatiblePlatform
, DistroNotFound , DistroNotFound

View File

@ -328,6 +328,7 @@ executable ghcup
, resourcet , resourcet
, string-interpolate , string-interpolate
, table-layout , table-layout
, template-haskell
, text , text
, uri-bytestring , uri-bytestring
, utf8-string , utf8-string

View File

@ -9,9 +9,14 @@ import Data.Versions
import URI.ByteString import URI.ByteString
import URI.ByteString.QQ import URI.ByteString.QQ
import qualified Data.Text as T
-- | This reflects the API version of the JSON. -- | This reflects the API version of the JSON.
ghcupURL :: URI ghcupURL :: URI
ghcupURL = [uri|https://www.haskell.org/ghcup/data/ghcup-0.0.1.json|] ghcupURL = [uri|https://www.haskell.org/ghcup/data/ghcup-0.0.1.json|]
ghcUpVer :: PVP ghcUpVer :: PVP
ghcUpVer = [pver|0.1.4|] ghcUpVer = [pver|0.1.4|]
numericVer :: String
numericVer = T.unpack . prettyPVP $ ghcUpVer