Skip to content

Commit

Permalink
Add subcommand to output system requirements in markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Nov 12, 2022
1 parent 32a75b4 commit 1b9f1fc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ghcup-0.0.7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ toolRequirements:
unknown_versioning:
distroPKGs: []
notes: On Windows, msys2 should already have been set up during the installation,
so most users should just press ENTER.
so most users should just proceed.
If you are installing manually, make sure to have a working mingw64 toolchain and
shell.
ghcupDownloads:
Expand Down
Binary file modified ghcup-0.0.7.yaml.sig
Binary file not shown.
54 changes: 53 additions & 1 deletion ghcup-gen/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Generate where

import GHCup
import GHCup.Download
import GHCup.Requirements
import GHCup.Errors
import GHCup.Types
import GHCup.Types.Optics
Expand Down Expand Up @@ -144,13 +145,14 @@ generateTable output = do
handle <- case output of
StdOut -> pure stdout
FileOutput fp -> liftIO $ openFile fp WriteMode

forM_ [GHC,Cabal,HLS,Stack] $ \tool -> do
case tool of
GHC -> liftIO $ hPutStrLn handle $ "<details> <summary>Show all supported <a href='https://www.haskell.org/ghc/'>GHC</a> versions</summary>"
Cabal -> liftIO $ hPutStrLn handle $ "<details> <summary>Show all supported <a href='https://cabal.readthedocs.io/en/stable/'>cabal-install</a> versions</summary>"
HLS -> liftIO $ hPutStrLn handle $ "<details> <summary>Show all supported <a href='https://haskell-language-server.readthedocs.io/en/stable/'>HLS</a> versions</summary>"
Stack -> liftIO $ hPutStrLn handle $ "<details> <summary>Show all supported <a href='https://docs.haskellstack.org/en/stable/README/'>Stack</a> versions</summary>"
_ -> fail "no"
liftIO $ hPutStrLn handle $ "<table>"
liftIO $ hPutStrLn handle $ "<thead><tr><th>" <> show tool <> " Version</th><th>Tags</th></tr></thead>"
liftIO $ hPutStrLn handle $ "<tbody>"
Expand All @@ -175,3 +177,53 @@ generateTable output = do
printTag (Base pvp'') = "base-" ++ T.unpack (prettyPVP pvp'')
printTag (UnknownTag t ) = t
printTag Old = ""


generateSystemInfo :: ( MonadFail m
, MonadMask m
, Monad m
, MonadReader env m
, HasSettings env
, HasDirs env
, HasLog env
, MonadThrow m
, MonadIO m
, HasPlatformReq env
, HasGHCupInfo env
, MonadUnliftIO m
)
=> Output
-> m ExitCode
generateSystemInfo output = do
handle <- case output of
StdOut -> pure stdout
FileOutput fp -> liftIO $ openFile fp WriteMode

forM_ [ Linux Debian
, Linux Ubuntu
, Linux Fedora
, Linux CentOS
, Linux Alpine
, Linux UnknownLinux
, Darwin
, FreeBSD
, Windows
] $ \plat -> do
GHCupInfo { .. } <- getGHCupInfo
(Just req) <- pure $ getCommonRequirements (PlatformResult plat Nothing) _toolRequirements
liftIO $ hPutStrLn handle $ "### " <> (prettyPlat plat) <> "\n"
liftIO $ hPutStrLn handle $ (T.unpack $ pretty' req) <> "\n"
pure ExitSuccess
where
pretty' Requirements {..} =
let d = if not . null $ _distroPKGs
then "The following distro packages are required: " <> "`" <> T.intercalate " " _distroPKGs <> "`"
else ""
n = if not . T.null $ _notes then _notes else ""
in if | T.null d -> n
| T.null n -> d
| otherwise -> d <> "\n" <> n

prettyPlat (Linux UnknownLinux) = "Linux (generic)"
prettyPlat p = show p

10 changes: 9 additions & 1 deletion ghcup-gen/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ data Command = ValidateYAML ValidateYAMLOpts
| ValidateTarballs ValidateYAMLOpts TarballFilter
| GenerateHlsGhc ValidateYAMLOpts Format Output
| GenerateToolTable ValidateYAMLOpts Output
| GenerateSystemDepsInfo ValidateYAMLOpts Output


fileOutput :: Parser Output
Expand Down Expand Up @@ -152,11 +153,17 @@ com = subparser
(progDesc "Generate a list of HLS-GHC support")
)
<> command
"generate-table"
"generate-tool-table"
(info
((GenerateToolTable <$> validateYAMLOpts <*> outputP) <**> helper)
(progDesc "Generate a markdown table of available tool versions")
)
<> command
"generate-system-deps-info"
(info
((GenerateSystemDepsInfo <$> validateYAMLOpts <*> outputP) <**> helper)
(progDesc "Generate a markdown info for system dependencies")
)
)


Expand Down Expand Up @@ -202,6 +209,7 @@ main = do
ValidateTarballs vopts tarballFilter -> withValidateYamlOpts vopts (validateTarballs tarballFilter)
GenerateHlsGhc vopts format output -> withValidateYamlOpts vopts (generateHLSGhc format output)
GenerateToolTable vopts output -> withValidateYamlOpts vopts (generateTable output)
GenerateSystemDepsInfo vopts output -> withValidateYamlOpts vopts (generateSystemInfo output)
pure ()

where

0 comments on commit 1b9f1fc

Please sign in to comment.