on d4e9599 help sign in
65 lines 1.9 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Exit.Diff
3 ( Exit(..)
4 , toReport
5 )
6 where
8import qualified Data.List as List
9import qualified Text.PrettyPrint.ANSI.Leijen as P
11import qualified Elm.Package as Pkg
12import qualified Reporting.Exit.Help as Help
16-- EXITS
19data Exit
20 = Application
21 | UnknownPackage Pkg.Name [Pkg.Name]
22 | UnknownVersion Pkg.Name Pkg.Version [Pkg.Version]
26-- TO DOC
29toReport :: Exit -> Help.Report
30toReport exit =
31 case exit of
32 Application ->
33 Help.report "CANNOT DIFF APPLICATIONS" Nothing
34 "I cannot perform diffs on applications, only packages! If you are\
35 \ just curious to see a diff, try running this command:"
36 [ P.indent 4 $ P.green $ "elm diff elm-lang/html 5.1.1 6.0.0"
37 ]
39 UnknownPackage pkg suggestions ->
40 Help.report "UNKNOWN PACKAGE" Nothing
41 ( "I cannot find a package called:"
42 )
43 [ P.indent 4 $ P.red $ P.text $ Pkg.toString pkg
44 , "Maybe you want one of these instead?"
45 , P.indent 4 $ P.dullyellow $ P.vcat $ map (P.text . Pkg.toString) suggestions
46 , "But check <https://package.elm-lang.org> to see all possibilities!"
47 ]
49 UnknownVersion _pkg vsn realVersions ->
50 Help.docReport "UNKNOWN VERSION" Nothing
51 ( P.fillSep $
52 [ "Version", P.red (P.text (Pkg.versionToString vsn))
53 , "has", "never", "been", "published,", "so", "I"
54 , "cannot", "diff", "against", "it."
55 ]
56 )
57 [ "Here are all the versions that HAVE been published:"
58 , P.indent 4 $ P.dullyellow $ P.vcat $
59 let
60 sameMajor v1 v2 = Pkg._major v1 == Pkg._major v2
61 mkRow vsns = P.hsep $ map (P.text . Pkg.versionToString) vsns
62 in
63 map mkRow $ List.groupBy sameMajor (List.sort realVersions)
64 , "Want one of those instead?"
65 ]