@@ -46,13 +46,17 @@ data ProgramsOfInterest = ProgramsOfInterest
46
46
showProgramVersionOfInterest :: ProgramsOfInterest -> String
47
47
showProgramVersionOfInterest ProgramsOfInterest {.. } =
48
48
unlines
49
- [ " cabal: \t\t " ++ showVersionWithDefault cabalVersion
50
- , " stack: \t\t " ++ showVersionWithDefault stackVersion
51
- , " ghc: \t\t " ++ showVersionWithDefault ghcVersion
49
+ [ showProgramVersion " cabal" cabalVersion
50
+ , showProgramVersion " stack" stackVersion
51
+ , showProgramVersion " ghc" ghcVersion
52
52
]
53
+
54
+ showProgramVersion :: String -> Maybe Version -> String
55
+ showProgramVersion name version =
56
+ pad 16 (name ++ " :" ) ++ showVersionWithDefault version
53
57
where
54
- showVersionWithDefault :: Maybe Version -> String
55
58
showVersionWithDefault = maybe " Not found" showVersion
59
+ pad n s = s ++ replicate (n - length s) ' '
56
60
57
61
findProgramVersions :: IO ProgramsOfInterest
58
62
findProgramVersions = ProgramsOfInterest
@@ -69,8 +73,11 @@ findVersionOf tool =
69
73
Nothing -> pure Nothing
70
74
Just path ->
71
75
readProcessWithExitCode path [" --numeric-version" ] " " >>= \ case
72
- (ExitSuccess , sout, _) -> pure $ consumeParser myVersionParser sout
76
+ (ExitSuccess , sout, _) -> pure $ mkVersion sout
73
77
_ -> pure Nothing
78
+
79
+ mkVersion :: String -> Maybe Version
80
+ mkVersion = consumeParser myVersionParser
74
81
where
75
82
myVersionParser = do
76
83
skipSpaces
@@ -79,4 +86,5 @@ findVersionOf tool =
79
86
pure version
80
87
81
88
consumeParser :: ReadP a -> String -> Maybe a
82
- consumeParser p input = listToMaybe $ map fst . filter (null . snd ) $ readP_to_S p input
89
+ consumeParser p input =
90
+ listToMaybe $ map fst . filter (null . snd ) $ readP_to_S p input
0 commit comments