2021-10-15 20:24:23 +00:00
{- # LANGUAGE CPP # -}
{- # LANGUAGE DataKinds # -}
{- # LANGUAGE FlexibleContexts # -}
{- # LANGUAGE OverloadedStrings # -}
{- # LANGUAGE DuplicateRecordFields # -}
module GHCup.OptParse (
module GHCup.OptParse.Common
, module GHCup.OptParse.Install
2023-01-08 11:29:35 +00:00
, module GHCup.OptParse.Test
2021-10-15 20:24:23 +00:00
, module GHCup.OptParse.Set
, module GHCup.OptParse.UnSet
, module GHCup.OptParse.Rm
, module GHCup.OptParse.Compile
, module GHCup.OptParse.Config
, module GHCup.OptParse.Whereis
, module GHCup.OptParse.List
2022-01-28 22:08:35 +00:00
# ifndef DISABLE_UPGRADE
2021-10-15 20:24:23 +00:00
, module GHCup.OptParse.Upgrade
2022-01-28 22:08:35 +00:00
# endif
2021-10-15 20:24:23 +00:00
, module GHCup.OptParse.ChangeLog
, module GHCup.OptParse.Prefetch
, module GHCup.OptParse.GC
, module GHCup.OptParse.DInfo
, module GHCup.OptParse.Nuke
, module GHCup.OptParse.ToolRequirements
2022-02-09 17:57:59 +00:00
, module GHCup.OptParse.Run
2021-10-15 20:24:23 +00:00
, module GHCup.OptParse
) where
import GHCup.OptParse.Common
import GHCup.OptParse.Install
2023-01-08 11:29:35 +00:00
import GHCup.OptParse.Test
2021-10-15 20:24:23 +00:00
import GHCup.OptParse.Set
import GHCup.OptParse.UnSet
import GHCup.OptParse.Rm
2022-02-09 17:57:59 +00:00
import GHCup.OptParse.Run
2021-10-15 20:24:23 +00:00
import GHCup.OptParse.Compile
import GHCup.OptParse.Config
import GHCup.OptParse.Whereis
import GHCup.OptParse.List
2022-01-28 22:08:35 +00:00
# ifndef DISABLE_UPGRADE
2021-10-15 20:24:23 +00:00
import GHCup.OptParse.Upgrade
2022-01-28 22:08:35 +00:00
# endif
2021-10-15 20:24:23 +00:00
import GHCup.OptParse.ChangeLog
import GHCup.OptParse.Prefetch
import GHCup.OptParse.GC
import GHCup.OptParse.DInfo
import GHCup.OptParse.ToolRequirements
import GHCup.OptParse.Nuke
import GHCup.Types
# if ! MIN_VERSION_base ( 4 , 13 , 0 )
import Control.Monad.Fail ( MonadFail )
# endif
import Control.Monad.Reader
import Data.Bifunctor
import Data.Either
import Data.Functor
import Data.Maybe
import Options.Applicative hiding ( style )
import Options.Applicative.Help.Pretty ( text )
import Prelude hiding ( appendFile )
import URI.ByteString
import qualified Data.ByteString.UTF8 as UTF8
data Options = Options
{
-- global options
optVerbose :: Maybe Bool
, optCache :: Maybe Bool
2021-10-30 11:23:02 +00:00
, optMetaCache :: Maybe Integer
2023-01-01 11:04:00 +00:00
, optMetaMode :: Maybe MetaMode
2022-11-12 06:12:13 +00:00
, optPlatform :: Maybe PlatformRequest
2021-10-15 20:24:23 +00:00
, optUrlSource :: Maybe URI
, optNoVerify :: Maybe Bool
, optKeepDirs :: Maybe KeepDirs
, optsDownloader :: Maybe Downloader
, optNoNetwork :: Maybe Bool
, optGpg :: Maybe GPGSetting
-- commands
, optCommand :: Command
}
data Command
= Install ( Either InstallCommand InstallOptions )
2023-01-08 11:29:35 +00:00
| Test TestCommand
2021-10-15 20:24:23 +00:00
| InstallCabalLegacy InstallOptions
| Set ( Either SetCommand SetOptions )
| UnSet UnsetCommand
| List ListOptions
| Rm ( Either RmCommand RmOptions )
| DInfo
| Compile CompileCommand
| Config ConfigCommand
| Whereis WhereisOptions WhereisCommand
2022-01-28 22:08:35 +00:00
# ifndef DISABLE_UPGRADE
2022-05-02 17:54:37 +00:00
| Upgrade UpgradeOpts Bool Bool
2022-01-28 22:08:35 +00:00
# endif
2022-03-17 14:05:18 +00:00
| ToolRequirements ToolReqOpts
2021-10-15 20:24:23 +00:00
| ChangeLog ChangeLogOptions
| Nuke
# if defined ( BRICK )
| Interactive
# endif
| Prefetch PrefetchCommand
| GC GCOptions
2022-02-09 17:57:59 +00:00
| Run RunOptions
2022-12-19 16:10:19 +00:00
| PrintAppErrors
2021-10-15 20:24:23 +00:00
opts :: Parser Options
opts =
Options
2022-03-13 21:48:45 +00:00
<$> invertableSwitch " verbose " ( Just 'v' ) False ( help " Enable verbosity (default: disabled) " )
<*> invertableSwitch " cache " ( Just 'c' ) False ( help " Cache downloads in ~/.ghcup/cache (default: disabled) " )
2023-01-01 11:19:37 +00:00
<*> optional ( option auto ( long " metadata-caching " <> metavar " SEC " <> help " How long the yaml metadata caching interval is (in seconds), 0 to disable " ) )
2023-01-01 11:04:00 +00:00
<*> optional ( option auto ( long " metadata-fetching-mode " <> metavar " <Strict|Lax> " <> help " Whether to fail on metadata download failure (Strict) or fall back to cached version (Lax (default)) " ) )
2022-11-12 06:12:13 +00:00
<*> optional
( option
( eitherReader platformParser )
( short 'p'
<> long " platform "
<> metavar " PLATFORM "
<> help
" Override for platform (triple matching ghc tarball names), e.g. x86_64-fedora27-linux "
)
)
2021-10-15 20:24:23 +00:00
<*> optional
( option
( eitherReader parseUri )
( short 's'
<> long " url-source "
<> metavar " URL "
<> help " Alternative ghcup download info url "
<> internal
2022-03-05 19:00:32 +00:00
<> completer fileUri
2021-10-15 20:24:23 +00:00
)
)
2022-03-13 21:48:45 +00:00
<*> ( fmap . fmap ) not ( invertableSwitch " verify " ( Just 'n' ) True ( help " Disable tarball checksum verification (default: enabled) " ) )
2021-10-15 20:24:23 +00:00
<*> optional ( option
( eitherReader keepOnParser )
( long " keep "
<> metavar " <always|errors|never> "
<> help
" Keep build directories? (default: errors) "
<> hidden
2022-03-05 19:00:32 +00:00
<> completer ( listCompleter [ " always " , " errors " , " never " ] )
2021-10-15 20:24:23 +00:00
) )
<*> optional ( option
( eitherReader downloaderParser )
( long " downloader "
# if defined ( INTERNAL_DOWNLOADER )
<> metavar " <internal|curl|wget> "
<> help
" Downloader to use (default: internal) "
2022-03-05 19:14:10 +00:00
<> completer ( listCompleter [ " internal " , " curl " , " wget " ] )
2021-10-15 20:24:23 +00:00
# else
<> metavar " <curl|wget> "
<> help
" Downloader to use (default: curl) "
2022-03-05 19:14:10 +00:00
<> completer ( listCompleter [ " curl " , " wget " ] )
2021-10-15 20:24:23 +00:00
# endif
<> hidden
) )
2022-03-13 21:48:45 +00:00
<*> invertableSwitch " offline " ( Just 'o' ) False ( help " Don't do any network calls, trying cached assets and failing if missing. " )
2021-10-15 20:24:23 +00:00
<*> optional ( option
( eitherReader gpgParser )
( long " gpg "
<> metavar " <strict|lax|none> "
<> help
" GPG verification (default: none) "
2022-03-05 19:00:32 +00:00
<> completer ( listCompleter [ " strict " , " lax " , " none " ] )
2021-10-15 20:24:23 +00:00
) )
<*> com
where
parseUri s' =
first show $ parseURI strictURIParserOptions ( UTF8 . fromString s' )
com :: Parser Command
com =
subparser
# if defined ( BRICK )
( command
" tui "
( ( \ _ -> Interactive )
<$> info
helper
( progDesc " Start the interactive GHCup UI "
)
)
<> command
# else
( command
# endif
" install "
( Install
<$> info
( installParser <**> helper )
( progDesc " Install or update GHC/cabal/HLS/stack "
<> footerDoc ( Just $ text installToolFooter )
)
)
2023-01-08 11:29:35 +00:00
<> command
" test "
( info
( Test <$> testParser <**> helper )
( progDesc " Run tests for a tool (if any) [EXPERIMENTAL!] "
<> footerDoc ( Just $ text testFooter )
)
)
2021-10-15 20:24:23 +00:00
<> command
" set "
( info
( Set <$> setParser <**> helper )
( progDesc " Set currently active GHC/cabal version "
<> footerDoc ( Just $ text setFooter )
)
)
<> command
" unset "
( info
( UnSet <$> unsetParser <**> helper )
( progDesc " Unset currently active GHC/cabal version "
<> footerDoc ( Just $ text unsetFooter )
)
)
<> command
" rm "
( info
( Rm <$> rmParser <**> helper )
( progDesc " Remove a GHC/cabal/HLS/stack version "
<> footerDoc ( Just $ text rmFooter )
)
)
<> command
" list "
( info ( List <$> listOpts <**> helper )
( progDesc " Show available GHCs and other tools " )
)
<> command
" upgrade "
( info
( ( Upgrade <$> upgradeOptsP <*> switch
( short 'f' <> long " force " <> help " Force update " )
2022-05-02 17:54:37 +00:00
<*> switch
( long " fail-if-shadowed " <> help " Fails after upgrading if the upgraded ghcup binary is shadowed by something else in PATH (useful for CI) " )
2021-10-15 20:24:23 +00:00
)
<**> helper
)
( progDesc " Upgrade ghcup " )
)
<> command
" compile "
( Compile
<$> info ( compileP <**> helper )
( progDesc " Compile a tool from source " )
)
<> command
" whereis "
( info
( ( Whereis
<$> ( WhereisOptions <$> switch ( short 'd' <> long " directory " <> help " return directory of the binary instead of the binary location " ) )
<*> whereisP
) <**> helper
)
( progDesc " Find a tools location "
<> footerDoc ( Just $ text whereisFooter ) )
)
<> command
" prefetch "
( info
( ( Prefetch
<$> prefetchP
) <**> helper
)
( progDesc " Prefetch assets "
<> footerDoc ( Just $ text prefetchFooter ) )
)
<> command
" gc "
( info
( ( GC
<$> gcP
) <**> helper
)
( progDesc " Garbage collection "
<> footerDoc ( Just $ text gcFooter ) )
)
2022-02-09 17:57:59 +00:00
<> command
" run "
( Run
<$>
info
( runOpts <**> helper )
( progDesc " Run a command with the given tool in PATH "
<> footerDoc ( Just $ text runFooter )
)
)
2021-10-15 20:24:23 +00:00
<> commandGroup " Main commands: "
)
<|> subparser
( command
" debug-info "
( ( \ _ -> DInfo ) <$> info helper ( progDesc " Show debug info " ) )
<> command
" tool-requirements "
2022-03-17 14:05:18 +00:00
( ToolRequirements
<$> info ( toolReqP <**> helper )
2021-10-15 20:24:23 +00:00
( progDesc " Show the requirements for ghc/cabal " )
)
<> command
" changelog "
( info
( fmap ChangeLog changelogP <**> helper )
( progDesc " Find/show changelog "
<> footerDoc ( Just $ text changeLogFooter )
)
)
<> command
" config "
( Config
<$> info ( configP <**> helper )
( progDesc " Show or set config " <> footerDoc ( Just $ text configFooter ) )
)
<> commandGroup " Other commands: "
<> hidden
)
<|> subparser
( command
" install-cabal "
( info
( ( InstallCabalLegacy <$> installOpts ( Just Cabal ) ) <**> helper )
( progDesc " Install or update cabal "
<> footerDoc ( Just $ text installCabalFooter )
)
)
<> internal
)
<|> subparser
( command
" nuke "
( info ( pure Nuke <**> helper )
( progDesc " Completely remove ghcup from your system " ) )
<> commandGroup " Nuclear Commands: "
<> hidden
)
2022-12-19 16:10:19 +00:00
<|> subparser
( command
" print-app-errors "
( info ( pure PrintAppErrors <**> helper )
( progDesc " " ) )
<> internal
)