From 124ddcdfeba8a3a89f0bbf7b47e8364f5f6c1679 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 12 Apr 2020 12:11:24 +0200 Subject: [PATCH] Mimic the old ghcup cli options So we don't break scripts. --- README.md | 8 +-- app/ghcup/Main.hs | 139 +++++++++++++++++++++++----------------------- bootstrap-haskell | 4 +- 3 files changed, 76 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 0fb7c1b..ba575d9 100644 --- a/README.md +++ b/README.md @@ -45,16 +45,16 @@ Common use cases are: ghcup list # install the recommended GHC version -ghcup install ghc +ghcup install # install a specific GHC version -ghcup install ghc -v 8.2.2 +ghcup install 8.2.2 # set the currently "active" GHC version -ghcup set -v 8.4.4 +ghcup set 8.4.4 # install cabal-install -ghcup install cabal +ghcup install-cabal # update ghcup itself ghcup upgrade diff --git a/app/ghcup/Main.hs b/app/ghcup/Main.hs index 2078eee..3bc30fc 100644 --- a/app/ghcup/Main.hs +++ b/app/ghcup/Main.hs @@ -73,7 +73,8 @@ data Options = Options } data Command - = Install InstallCommand + = Install InstallOptions + | InstallCabal InstallOptions | SetGHC SetGHCOptions | List ListOptions | Rm RmOptions @@ -87,9 +88,6 @@ data ToolVersion = ToolVersion Version | ToolTag Tag -data InstallCommand = InstallGHC InstallOptions - | InstallCabal InstallOptions - data InstallOptions = InstallOptions { instVer :: Maybe ToolVersion , instPlatform :: Maybe PlatformRequest @@ -164,11 +162,29 @@ com = subparser ( command "install" - ( Install - <$> (info (installP <**> helper) - (progDesc "Install or update GHC/cabal") - ) + ((info ((Install <$> installOpts) <**> helper) + (progDesc "Install or update GHC") + ) ) + <> command + "set" + ( SetGHC + <$> (info (setGHCOpts <**> helper) + (progDesc "Set currently active GHC version") + ) + ) + <> command + "rm" + ( Rm + <$> (info (rmOpts <**> helper) (progDesc "Remove a GHC version")) + ) + + <> command + "install-cabal" + ((info ((InstallCabal <$> installOpts) <**> helper) + (progDesc "Install or update cabal") + ) + ) <> command "list" ( List @@ -179,10 +195,7 @@ com = <> command "upgrade" ( Upgrade - <$> (info - (upgradeOptsP <**> helper) - (progDesc "Upgrade ghcup (per default in ~/.ghcup/bin/)") - ) + <$> (info (upgradeOptsP <**> helper) (progDesc "Upgrade ghcup")) ) <> command "compile" @@ -193,25 +206,6 @@ com = ) <> commandGroup "Main commands:" ) - <|> subparser - ( command - "set" - ( SetGHC - <$> (info (setGHCOpts <**> helper) - (progDesc "Set the currently active GHC version") - ) - ) - <> command - "rm" - ( Rm - <$> (info - (rmOpts <**> helper) - (progDesc "Remove a GHC version installed by ghcup") - ) - ) - <> commandGroup "GHC commands:" - <> hidden - ) <|> subparser ( command "debug-info" @@ -224,34 +218,19 @@ com = <> command "tool-requirements" ( (\_ -> ToolRequirements) - <$> (info (helper) (progDesc "Show the requirements for ghc/cabal")) + <$> (info (helper) + (progDesc "Show the requirements for ghc/cabal") + ) ) <> commandGroup "Other commands:" <> hidden ) -installP :: Parser InstallCommand -installP = subparser - ( command - "ghc" - ( InstallGHC - <$> (info (installOpts <**> helper) (progDesc "Install a GHC version")) - ) - <> command - "cabal" - ( InstallCabal - <$> (info (installOpts <**> helper) - (progDesc "Install or update a Cabal version") - ) - ) - ) - installOpts :: Parser InstallOptions installOpts = - InstallOptions - <$> optional toolVersionParser - <*> (optional + (flip InstallOptions) + <$> (optional (option (eitherReader platformParser) ( short 'p' @@ -262,10 +241,11 @@ installOpts = ) ) ) + <*> optional toolVersionArgument setGHCOpts :: Parser SetGHCOptions -setGHCOpts = SetGHCOptions <$> optional toolVersionParser +setGHCOpts = SetGHCOptions <$> optional toolVersionArgument listOpts :: Parser ListOptions listOpts = @@ -289,7 +269,7 @@ listOpts = ) rmOpts :: Parser RmOptions -rmOpts = RmOptions <$> versionParser +rmOpts = RmOptions <$> versionArgument compileP :: Parser CompileCommand @@ -370,13 +350,6 @@ compileOpts = ) -versionParser :: Parser Version -versionParser = option - (eitherReader (bimap (const "Not a valid version") id . version . T.pack)) - (short 'v' <> long "version" <> metavar "VERSION" <> help "The target version" - ) - - toolVersionParser :: Parser ToolVersion toolVersionParser = verP <|> toolP where @@ -384,16 +357,44 @@ toolVersionParser = verP <|> toolP toolP = ToolTag <$> (option - (eitherReader - (\s' -> case fmap toLower s' of - "recommended" -> Right Recommended - "latest" -> Right Latest - other -> Left ([i|Unknown tag #{other}|]) - ) - ) + (eitherReader tagEither) (short 't' <> long "tag" <> metavar "TAG" <> help "The target tag") ) +-- | same as toolVersionParser, except as an argument. +toolVersionArgument :: Parser ToolVersion +toolVersionArgument = + argument (eitherReader toolVersionEither) (metavar "VERSION|TAG") + + +versionArgument :: Parser Version +versionArgument = argument + (eitherReader versionEither) + (metavar "VERSION") + +versionParser :: Parser Version +versionParser = option + (eitherReader versionEither) + (short 'v' <> long "version" <> metavar "VERSION" <> help "The target version" + ) + +tagEither :: String -> Either String Tag +tagEither s' = case fmap toLower s' of + "recommended" -> Right Recommended + "latest" -> Right Latest + other -> Left ([i|Unknown tag #{other}|]) + +versionEither :: String -> Either String Version +versionEither s' = + -- 'version' is a bit too lax and will parse typoed tags + case readMaybe ((:[]) . head $ s') :: Maybe Int of + Just _ -> bimap (const "Not a valid version") id . version . T.pack $ s' + Nothing -> Left "Not a valid version" + +toolVersionEither :: String -> Either String ToolVersion +toolVersionEither s' = + bimap id ToolTag (tagEither s') <|> bimap id ToolVersion (versionEither s') + toolParser :: String -> Either String Tool toolParser s' | t == T.pack "ghc" = Right GHC @@ -646,7 +647,7 @@ main = do runLogger $ checkForUpdates dls case optCommand of - Install (InstallGHC InstallOptions {..}) -> + Install (InstallOptions {..}) -> void $ (runInstTool $ do v <- liftE $ fromVersion dls instVer GHC @@ -669,7 +670,7 @@ Check the logs at ~/.ghcup/logs and the build directory #{tmpdir} for more clues $(logError) [i|#{e}|] $(logError) [i|Also check the logs in ~/.ghcup/logs|] exitFailure - Install (InstallCabal InstallOptions {..}) -> + InstallCabal (InstallOptions {..}) -> void $ (runInstTool $ do v <- liftE $ fromVersion dls instVer Cabal diff --git a/bootstrap-haskell b/bootstrap-haskell index f1d14e6..4a3f1d3 100755 --- a/bootstrap-haskell +++ b/bootstrap-haskell @@ -107,10 +107,10 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then read -r answer