Skip to content

Commit

Permalink
Improve distro code
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Oct 23, 2023
1 parent f9a2b21 commit 34f72b4
Show file tree
Hide file tree
Showing 3 changed files with 1,029 additions and 1,097 deletions.
16 changes: 2 additions & 14 deletions lib-opt/GHCup/OptParse/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,7 @@ platformParser s' = case MP.parse (platformP <* MP.eof) "" (T.pack s') of
)
]
distroP :: MP.Parsec Void Text LinuxDistro
distroP = choice'
[ MP.chunk "debian" $> Debian
, MP.chunk "deb" $> Debian
, MP.chunk "ubuntu" $> Ubuntu
, MP.chunk "mint" $> Mint
, MP.chunk "fedora" $> Fedora
, MP.chunk "centos" $> CentOS
, MP.chunk "redhat" $> RedHat
, MP.chunk "alpine" $> Alpine
, MP.chunk "gentoo" $> Gentoo
, MP.chunk "exherbo" $> Exherbo
, MP.chunk "unknown" $> UnknownLinux
]
distroP = choice' ((\d -> MP.chunk (T.pack $ distroToString d) $> d) <$> allDistros)


uriParser :: String -> Either String URI
Expand Down Expand Up @@ -367,7 +355,7 @@ fileUri' add = \case
-- We need to do this so bash doesn't expand out any ~ or other
-- chars we want to complete on, or emit an end of line error
-- when seeking the close to the quote.
--
--
-- NOTE: copied from https://hackage.haskell.org/package/optparse-applicative-0.17.0.0/docs/src/Options.Applicative.Builder.Completer.html#requote
requote :: String -> String
requote s =
Expand Down
13 changes: 8 additions & 5 deletions lib/GHCup/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,18 @@ data LinuxDistro = Debian
| RedHat
| Alpine
| AmazonLinux
| RockyLinux
| VoidLinux
| Rocky
| Void
-- rolling
| Gentoo
| Exherbo
-- not known
| UnknownLinux
-- ^ must exit
deriving (Eq, GHC.Generic, Ord, Show)
deriving (Eq, GHC.Generic, Ord, Show, Enum, Bounded)

allDistros :: [LinuxDistro]
allDistros = enumFromTo minBound maxBound

instance NFData LinuxDistro

Expand All @@ -270,8 +273,8 @@ distroToString CentOS = "centos"
distroToString RedHat = "redhat"
distroToString Alpine = "alpine"
distroToString AmazonLinux = "amazon"
distroToString RockyLinux = "rocky"
distroToString VoidLinux = "void"
distroToString Rocky = "rocky"
distroToString Void = "void"
distroToString Gentoo = "gentoo"
distroToString Exherbo = "exherbo"
distroToString UnknownLinux = "unknown"
Expand Down
Loading

0 comments on commit 34f72b4

Please sign in to comment.