Improve distro code

This commit is contained in:
Julian Ospald 2023-10-22 00:04:04 +08:00
parent f9a2b21cb0
commit 0adb602a96
No known key found for this signature in database
GPG Key ID: 4275CDA6A29BED43
3 changed files with 993 additions and 1061 deletions

View File

@ -209,19 +209,7 @@ platformParser s' = case MP.parse (platformP <* MP.eof) "" (T.pack s') of
) )
] ]
distroP :: MP.Parsec Void Text LinuxDistro distroP :: MP.Parsec Void Text LinuxDistro
distroP = choice' distroP = choice' ((\d -> MP.chunk (T.pack $ distroToString d) $> d) <$> allDistros)
[ 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
]
uriParser :: String -> Either String URI uriParser :: String -> Either String URI
@ -367,7 +355,7 @@ fileUri' add = \case
-- We need to do this so bash doesn't expand out any ~ or other -- 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 -- chars we want to complete on, or emit an end of line error
-- when seeking the close to the quote. -- 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 -- 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 :: String -> String
requote s = requote s =

View File

@ -249,15 +249,18 @@ data LinuxDistro = Debian
| RedHat | RedHat
| Alpine | Alpine
| AmazonLinux | AmazonLinux
| RockyLinux | Rocky
| VoidLinux | Void
-- rolling -- rolling
| Gentoo | Gentoo
| Exherbo | Exherbo
-- not known -- not known
| UnknownLinux | UnknownLinux
-- ^ must exit -- ^ 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 instance NFData LinuxDistro
@ -270,8 +273,8 @@ distroToString CentOS = "centos"
distroToString RedHat = "redhat" distroToString RedHat = "redhat"
distroToString Alpine = "alpine" distroToString Alpine = "alpine"
distroToString AmazonLinux = "amazon" distroToString AmazonLinux = "amazon"
distroToString RockyLinux = "rocky" distroToString Rocky = "rocky"
distroToString VoidLinux = "void" distroToString Void = "void"
distroToString Gentoo = "gentoo" distroToString Gentoo = "gentoo"
distroToString Exherbo = "exherbo" distroToString Exherbo = "exherbo"
distroToString UnknownLinux = "unknown" distroToString UnknownLinux = "unknown"

File diff suppressed because it is too large Load Diff