Mimic the old ghcup cli options

So we don't break scripts.
This commit is contained in:
Julian Ospald 2020-04-12 12:11:24 +02:00
parent 5c0a0fc155
commit 124ddcdfeb
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
3 changed files with 76 additions and 75 deletions

View File

@ -45,16 +45,16 @@ Common use cases are:
ghcup list ghcup list
# install the recommended GHC version # install the recommended GHC version
ghcup install ghc ghcup install
# install a specific GHC version # install a specific GHC version
ghcup install ghc -v 8.2.2 ghcup install 8.2.2
# set the currently "active" GHC version # set the currently "active" GHC version
ghcup set -v 8.4.4 ghcup set 8.4.4
# install cabal-install # install cabal-install
ghcup install cabal ghcup install-cabal
# update ghcup itself # update ghcup itself
ghcup upgrade ghcup upgrade

View File

@ -73,7 +73,8 @@ data Options = Options
} }
data Command data Command
= Install InstallCommand = Install InstallOptions
| InstallCabal InstallOptions
| SetGHC SetGHCOptions | SetGHC SetGHCOptions
| List ListOptions | List ListOptions
| Rm RmOptions | Rm RmOptions
@ -87,9 +88,6 @@ data ToolVersion = ToolVersion Version
| ToolTag Tag | ToolTag Tag
data InstallCommand = InstallGHC InstallOptions
| InstallCabal InstallOptions
data InstallOptions = InstallOptions data InstallOptions = InstallOptions
{ instVer :: Maybe ToolVersion { instVer :: Maybe ToolVersion
, instPlatform :: Maybe PlatformRequest , instPlatform :: Maybe PlatformRequest
@ -164,9 +162,27 @@ com =
subparser subparser
( command ( command
"install" "install"
( Install ((info ((Install <$> installOpts) <**> helper)
<$> (info (installP <**> helper) (progDesc "Install or update GHC")
(progDesc "Install or update GHC/cabal") )
)
<> 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 <> command
@ -179,10 +195,7 @@ com =
<> command <> command
"upgrade" "upgrade"
( Upgrade ( Upgrade
<$> (info <$> (info (upgradeOptsP <**> helper) (progDesc "Upgrade ghcup"))
(upgradeOptsP <**> helper)
(progDesc "Upgrade ghcup (per default in ~/.ghcup/bin/)")
)
) )
<> command <> command
"compile" "compile"
@ -193,25 +206,6 @@ com =
) )
<> commandGroup "Main commands:" <> 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 <|> subparser
( command ( command
"debug-info" "debug-info"
@ -224,34 +218,19 @@ com =
<> command <> command
"tool-requirements" "tool-requirements"
( (\_ -> ToolRequirements) ( (\_ -> ToolRequirements)
<$> (info (helper) (progDesc "Show the requirements for ghc/cabal")) <$> (info (helper)
(progDesc "Show the requirements for ghc/cabal")
)
) )
<> commandGroup "Other commands:" <> commandGroup "Other commands:"
<> hidden <> 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 :: Parser InstallOptions
installOpts = installOpts =
InstallOptions (flip InstallOptions)
<$> optional toolVersionParser <$> (optional
<*> (optional
(option (option
(eitherReader platformParser) (eitherReader platformParser)
( short 'p' ( short 'p'
@ -262,10 +241,11 @@ installOpts =
) )
) )
) )
<*> optional toolVersionArgument
setGHCOpts :: Parser SetGHCOptions setGHCOpts :: Parser SetGHCOptions
setGHCOpts = SetGHCOptions <$> optional toolVersionParser setGHCOpts = SetGHCOptions <$> optional toolVersionArgument
listOpts :: Parser ListOptions listOpts :: Parser ListOptions
listOpts = listOpts =
@ -289,7 +269,7 @@ listOpts =
) )
rmOpts :: Parser RmOptions rmOpts :: Parser RmOptions
rmOpts = RmOptions <$> versionParser rmOpts = RmOptions <$> versionArgument
compileP :: Parser CompileCommand 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 :: Parser ToolVersion
toolVersionParser = verP <|> toolP toolVersionParser = verP <|> toolP
where where
@ -384,15 +357,43 @@ toolVersionParser = verP <|> toolP
toolP = toolP =
ToolTag ToolTag
<$> (option <$> (option
(eitherReader (eitherReader tagEither)
(\s' -> case fmap toLower s' of (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 "recommended" -> Right Recommended
"latest" -> Right Latest "latest" -> Right Latest
other -> Left ([i|Unknown tag #{other}|]) other -> Left ([i|Unknown tag #{other}|])
)
) versionEither :: String -> Either String Version
(short 't' <> long "tag" <> metavar "TAG" <> help "The target tag") 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 :: String -> Either String Tool
@ -646,7 +647,7 @@ main = do
runLogger $ checkForUpdates dls runLogger $ checkForUpdates dls
case optCommand of case optCommand of
Install (InstallGHC InstallOptions {..}) -> Install (InstallOptions {..}) ->
void void
$ (runInstTool $ do $ (runInstTool $ do
v <- liftE $ fromVersion dls instVer GHC 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|#{e}|]
$(logError) [i|Also check the logs in ~/.ghcup/logs|] $(logError) [i|Also check the logs in ~/.ghcup/logs|]
exitFailure exitFailure
Install (InstallCabal InstallOptions {..}) -> InstallCabal (InstallOptions {..}) ->
void void
$ (runInstTool $ do $ (runInstTool $ do
v <- liftE $ fromVersion dls instVer Cabal v <- liftE $ fromVersion dls instVer Cabal

View File

@ -107,10 +107,10 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
read -r answer </dev/tty read -r answer </dev/tty
fi fi
eghcup --cache install ghc eghcup --cache install
eghcup set eghcup set
eghcup --cache install cabal eghcup --cache install-cabal
edo cabal new-update edo cabal new-update